Compare commits
2 Commits
6814e5e1f1
...
bf595e6c8a
| Author | SHA1 | Date | |
|---|---|---|---|
|
bf595e6c8a
|
|||
|
2aed03566c
|
@@ -30,6 +30,7 @@ add_executable(${APP_NAME}
|
|||||||
color.c
|
color.c
|
||||||
xcursor.c
|
xcursor.c
|
||||||
xwindow.c
|
xwindow.c
|
||||||
|
event.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# use C23
|
# use C23
|
||||||
|
|||||||
68
src/event.c
Normal file
68
src/event.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#include "event.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
#include <xcb/xcb_event.h>
|
||||||
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
#include "monitor.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "wm.h"
|
||||||
|
|
||||||
|
static void button_press(xcb_button_press_event_t *ev) {
|
||||||
|
if (ev->event == wm.current_monitor->bar_window) {
|
||||||
|
if (ev->event_x >= wm.current_monitor->tag_extent.start &&
|
||||||
|
ev->event_x <= wm.current_monitor->tag_extent.end) {
|
||||||
|
for (tag_t *tag = wm.current_monitor->tag_list; tag; tag = tag->next) {
|
||||||
|
if (ev->event_x >= tag->bar_extent.start &&
|
||||||
|
ev->event_x <= tag->bar_extent.end) {
|
||||||
|
monitor_select_tag(wm.current_monitor, tag->mask);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_xcb_event(xcb_generic_event_t *event) {
|
||||||
|
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event);
|
||||||
|
|
||||||
|
switch (event_type) {
|
||||||
|
#define EVENT(type, callback) \
|
||||||
|
case type: \
|
||||||
|
callback((void *)event); \
|
||||||
|
break
|
||||||
|
|
||||||
|
EVENT(XCB_BUTTON_PRESS, button_press);
|
||||||
|
|
||||||
|
#undef EVENT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean xcb_event_loop(GIOChannel *channel, GIOCondition condition,
|
||||||
|
gpointer user_data) {
|
||||||
|
if (condition & (G_IO_HUP | G_IO_ERR)) {
|
||||||
|
wm_quit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
xcb_generic_event_t *event = nullptr;
|
||||||
|
while ((event = xcb_poll_for_event(wm.xcb_conn))) {
|
||||||
|
handle_xcb_event(event);
|
||||||
|
p_delete(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_event_loop(void) {
|
||||||
|
int fd = xcb_get_file_descriptor(wm.xcb_conn);
|
||||||
|
GIOChannel *channel = g_io_channel_unix_new(fd);
|
||||||
|
g_io_channel_set_encoding(channel, nullptr, nullptr);
|
||||||
|
GIOCondition cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
|
||||||
|
g_io_add_watch(channel, cond, xcb_event_loop, nullptr);
|
||||||
|
g_io_channel_unref(channel);
|
||||||
|
}
|
||||||
3
src/event.h
Normal file
3
src/event.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void setup_event_loop(void);
|
||||||
@@ -41,6 +41,19 @@ uint32_t monitor_initialize_tag(monitor_t *monitor, const char **tags,
|
|||||||
return tag_count;
|
return tag_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void monitor_select_tag(monitor_t *monitor, uint32_t tag_mask) {
|
||||||
|
if (monitor->selected_tag->mask == tag_mask) return;
|
||||||
|
|
||||||
|
for (tag_t *tag = monitor->tag_list; tag; tag = tag->next) {
|
||||||
|
if (tag->mask == tag_mask) {
|
||||||
|
monitor->selected_tag = tag;
|
||||||
|
monitor_draw_bar(monitor);
|
||||||
|
xcb_flush(wm.xcb_conn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void tag_clean(tag_t *tag) {
|
static void tag_clean(tag_t *tag) {
|
||||||
tag_t *next_tag = nullptr;
|
tag_t *next_tag = nullptr;
|
||||||
for (tag_t *t = tag; t; t = next_tag) {
|
for (tag_t *t = tag; t; t = next_tag) {
|
||||||
|
|||||||
8
src/wm.c
8
src/wm.c
@@ -20,11 +20,13 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "default_config.h"
|
#include "default_config.h"
|
||||||
|
#include "event.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "xcursor.h"
|
#include "xcursor.h"
|
||||||
|
#include "xwindow.h"
|
||||||
|
|
||||||
static void wm_setup_signal(void);
|
static void wm_setup_signal(void);
|
||||||
static void wm_check_other_wm(void);
|
static void wm_check_other_wm(void);
|
||||||
@@ -176,6 +178,7 @@ static bool wm_detect_monitor_by_randr(void) {
|
|||||||
prev_monitor->next = monitor;
|
prev_monitor->next = monitor;
|
||||||
} else {
|
} else {
|
||||||
wm.monitor_list = monitor;
|
wm.monitor_list = monitor;
|
||||||
|
wm.current_monitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_monitor = monitor;
|
prev_monitor = monitor;
|
||||||
@@ -224,6 +227,7 @@ static bool wm_detect_monitor_by_xinerama(void) {
|
|||||||
prev_monitor->next = monitor;
|
prev_monitor->next = monitor;
|
||||||
} else {
|
} else {
|
||||||
wm.monitor_list = monitor;
|
wm.monitor_list = monitor;
|
||||||
|
wm.current_monitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_monitor = monitor;
|
prev_monitor = monitor;
|
||||||
@@ -246,6 +250,7 @@ void wm_detect_monitor(void) {
|
|||||||
monitor->geometry.height = wm.screen->height_in_pixels;
|
monitor->geometry.height = wm.screen->height_in_pixels;
|
||||||
|
|
||||||
wm.monitor_list = monitor;
|
wm.monitor_list = monitor;
|
||||||
|
wm.current_monitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_scan_clients(void) {}
|
void wm_scan_clients(void) {}
|
||||||
@@ -280,6 +285,7 @@ static void wm_setup(void) {
|
|||||||
monitor_draw_bar(m);
|
monitor_draw_bar(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xwindow_change_cursor(wm.screen->root, cursor_normal);
|
||||||
xcb_flush(wm.xcb_conn);
|
xcb_flush(wm.xcb_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,6 +339,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
debug_show_monitor_list();
|
debug_show_monitor_list();
|
||||||
|
|
||||||
|
setup_event_loop();
|
||||||
|
|
||||||
if (wm.loop == nullptr) {
|
if (wm.loop == nullptr) {
|
||||||
wm.loop = g_main_loop_new(nullptr, FALSE);
|
wm.loop = g_main_loop_new(nullptr, FALSE);
|
||||||
g_main_loop_run(wm.loop);
|
g_main_loop_run(wm.loop);
|
||||||
|
|||||||
@@ -100,3 +100,8 @@ visual_t *xwindow_get_xcb_visual(bool prefer_alpha) {
|
|||||||
|
|
||||||
return visual;
|
return visual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xwindow_change_cursor(xcb_window_t window, cursor_t cursor) {
|
||||||
|
xcb_params_cw_t params = {.cursor = xcursor_get_xcb_cursor(cursor)};
|
||||||
|
xcb_aux_change_window_attributes(wm.xcb_conn, window, XCB_CW_CURSOR, ¶ms);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,9 +3,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
#include "xcursor.h"
|
||||||
|
|
||||||
typedef struct visual_t {
|
typedef struct visual_t {
|
||||||
uint8_t depth;
|
uint8_t depth;
|
||||||
xcb_visualtype_t *visual;
|
xcb_visualtype_t *visual;
|
||||||
} visual_t;
|
} visual_t;
|
||||||
|
|
||||||
visual_t *xwindow_get_xcb_visual(bool prefer_alpha);
|
visual_t *xwindow_get_xcb_visual(bool prefer_alpha);
|
||||||
|
void xwindow_change_cursor(xcb_window_t window, cursor_t cursor);
|
||||||
|
|||||||
Reference in New Issue
Block a user