Improvements
This commit is contained in:
+39
-8
@@ -21,7 +21,7 @@ void cleanup(void) {
|
||||
// Keybind function to setup a key grab if the keycode is clicked along with the
|
||||
// MOD key
|
||||
void add_keybind(int key, int mod) {
|
||||
xcb_grab_key(conn, 0, scr->root, mod ? MOD : 0, key, XCB_GRAB_MODE_ASYNC,
|
||||
xcb_grab_key(conn, 0, scr->root, mod, key, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ void add_mousebind(int button, int mod) {
|
||||
xcb_grab_button(conn, 0, scr->root,
|
||||
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE,
|
||||
button, mod ? MOD : 0);
|
||||
button, mod);
|
||||
}
|
||||
|
||||
// Deploy function to initialize the X connection, set up event masks, and
|
||||
@@ -84,7 +84,38 @@ void subscribe(xcb_window_t win) {
|
||||
}
|
||||
|
||||
// Kill a window
|
||||
void kill(xcb_window_t window) { xcb_kill_client(conn, window); }
|
||||
void kill(xcb_window_t window) {
|
||||
xcb_intern_atom_cookie_t wm_protocols_cookie =
|
||||
xcb_intern_atom(conn, 1, 12, "WM_PROTOCOLS");
|
||||
xcb_intern_atom_cookie_t wm_delete_window_cookie =
|
||||
xcb_intern_atom(conn, 0, 16, "WM_DELETE_WINDOW");
|
||||
|
||||
xcb_intern_atom_reply_t *wm_protocols =
|
||||
xcb_intern_atom_reply(conn, wm_protocols_cookie, NULL);
|
||||
xcb_intern_atom_reply_t *wm_delete_window =
|
||||
xcb_intern_atom_reply(conn, wm_delete_window_cookie, NULL);
|
||||
|
||||
if (!wm_protocols || !wm_delete_window) {
|
||||
// fallback to force kill
|
||||
xcb_kill_client(conn, window);
|
||||
xcb_flush(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_client_message_event_t ev = {0};
|
||||
ev.response_type = XCB_CLIENT_MESSAGE;
|
||||
ev.window = window;
|
||||
ev.type = wm_protocols->atom;
|
||||
ev.format = 32;
|
||||
ev.data.data32[0] = wm_delete_window->atom;
|
||||
ev.data.data32[1] = XCB_CURRENT_TIME;
|
||||
|
||||
xcb_send_event(conn, 0, window, XCB_EVENT_MASK_NO_EVENT, (char *)&ev);
|
||||
xcb_flush(conn);
|
||||
|
||||
free(wm_protocols);
|
||||
free(wm_delete_window);
|
||||
}
|
||||
|
||||
// Destroy a window
|
||||
void destroy(xcb_window_t win) { xcb_destroy_window(conn, win); }
|
||||
@@ -111,12 +142,12 @@ Geometry get_geometry(xcb_window_t win) {
|
||||
}
|
||||
|
||||
// Get the current pointer position
|
||||
Geometry get_pointer(void) {
|
||||
PointerInfo get_pointer(void) {
|
||||
xcb_query_pointer_reply_t *geom;
|
||||
geom = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, scr->root), 0);
|
||||
Geometry g = {geom->root_x, geom->root_y, 0, 0};
|
||||
PointerInfo p = {geom->root_x, geom->root_y, geom->child};
|
||||
free(geom);
|
||||
return g;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Get the screen geometry
|
||||
@@ -301,7 +332,7 @@ Event translate_event(xcb_generic_event_t *ev) {
|
||||
ret.x = e->event_x;
|
||||
ret.y = e->event_y;
|
||||
ret.btn = e->detail;
|
||||
ret.state = (e->state & MOD) != 0;
|
||||
ret.state = e->state;
|
||||
} break;
|
||||
|
||||
case XCB_MOTION_NOTIFY: {
|
||||
@@ -326,7 +357,7 @@ Event translate_event(xcb_generic_event_t *ev) {
|
||||
ret.type = 9;
|
||||
ret.window = e->child;
|
||||
ret.btn = e->detail;
|
||||
ret.state = (e->state & MOD) != 0;
|
||||
ret.state = e->state;
|
||||
} break;
|
||||
|
||||
case XCB_KEY_RELEASE: {
|
||||
|
||||
+12
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
// Standard headers
|
||||
#include <err.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -36,6 +37,12 @@ typedef struct Geometry {
|
||||
uint16_t height;
|
||||
} Geometry;
|
||||
|
||||
typedef struct PointerInfo {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint32_t window;
|
||||
} PointerInfo;
|
||||
|
||||
// Event structure to represent various X events
|
||||
typedef struct Event {
|
||||
int32_t type;
|
||||
@@ -70,7 +77,7 @@ void hide(xcb_window_t window);
|
||||
void send_to_top(xcb_window_t win);
|
||||
|
||||
Geometry get_geometry(xcb_window_t win);
|
||||
Geometry get_pointer(void);
|
||||
PointerInfo get_pointer(void);
|
||||
Geometry get_screen(void);
|
||||
void free_geometry(Geometry *g);
|
||||
|
||||
@@ -93,4 +100,8 @@ void ungrab_pointer(void);
|
||||
xcb_generic_event_t *next_event(void);
|
||||
Event translate_event(xcb_generic_event_t *ev);
|
||||
|
||||
extern inline int mod() { return MOD; }
|
||||
extern inline int clk() { return XCB_MOD_MASK_LOCK; }
|
||||
extern inline int num() { return XCB_MOD_MASK_2; }
|
||||
|
||||
#endif // X_KUTU_H
|
||||
|
||||
Reference in New Issue
Block a user