Add remote commands support

This commit is contained in:
2025-10-29 17:27:23 +00:00
parent 11806119df
commit a21e716475
13 changed files with 238 additions and 115 deletions
+11 -36
View File
@@ -9,6 +9,9 @@ xcb_screen_t *scr;
// Currently focused window
xcb_window_t focuswin;
// Flush
void flush(void) { xcb_flush(conn); }
// Cleanup function to close the X connection on exit
void cleanup(void) {
if (conn != NULL)
@@ -81,34 +84,21 @@ void subscribe(xcb_window_t win) {
}
// Kill a window
void kill(xcb_window_t window) {
xcb_kill_client(conn, window);
xcb_flush(conn);
}
void kill(xcb_window_t window) { xcb_kill_client(conn, window); }
// Destroy a window
void destroy(xcb_window_t win) {
xcb_destroy_window(conn, win);
xcb_flush(conn);
}
void destroy(xcb_window_t win) { xcb_destroy_window(conn, win); }
// Show a window
void show(xcb_window_t window) {
xcb_map_window(conn, window);
xcb_flush(conn);
}
void show(xcb_window_t window) { xcb_map_window(conn, window); }
// Hide a window
void hide(xcb_window_t window) {
xcb_unmap_window(conn, window);
xcb_flush(conn);
}
void hide(xcb_window_t window) { xcb_unmap_window(conn, window); }
// Bring a window to the top of the stack
void send_to_top(xcb_window_t win) {
uint32_t values[1] = {XCB_STACK_MODE_ABOVE};
xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
xcb_flush(conn);
}
// Get the geometry of a window
@@ -139,7 +129,6 @@ Geometry get_screen(void) {
// the center)
void warp_pointer(xcb_window_t win, int x, int y) {
xcb_warp_pointer(conn, XCB_NONE, win, 0, 0, 0, 0, x, y);
xcb_flush(conn);
}
// Move a window to a specific position
@@ -147,7 +136,6 @@ void move_window(xcb_window_t win, int x, int y) {
uint32_t values[2] = {x, y};
xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
values);
xcb_flush(conn);
}
// Resize a window to specific dimensions
@@ -155,7 +143,6 @@ void resize_window(xcb_window_t win, int width, int height) {
uint32_t values[2] = {width, height};
xcb_configure_window(
conn, win, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
xcb_flush(conn);
}
xcb_size_hints_t get_wm_n_hints(xcb_window_t win) {
@@ -200,8 +187,6 @@ void set_wm_state(xcb_window_t win, int state) {
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, WM_STATE, WM_STATE, 32,
2, data);
xcb_flush(conn);
}
xcb_window_t draw_rectangle(int x, int y, int width, int height,
@@ -242,9 +227,6 @@ xcb_window_t draw_rectangle(int x, int y, int width, int height,
xcb_rectangle_t rect = {0, 0, width, height}; // relative to window
xcb_poly_fill_rectangle(conn, win, gc, 1, &rect);
// Flush the connection to send commands to the server
xcb_flush(conn);
return win;
}
@@ -257,25 +239,18 @@ void grab_pointer(xcb_window_t win) {
XCB_EVENT_MASK_POINTER_MOTION_HINT,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
XCB_CURRENT_TIME);
xcb_flush(conn);
}
void ungrab_pointer(void) {
xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
xcb_flush(conn);
}
void ungrab_pointer(void) { xcb_ungrab_pointer(conn, XCB_CURRENT_TIME); }
xcb_generic_event_t *next_event(void) { return xcb_poll_for_event(conn); }
// Wait for an event and return it as an Event structure
// This function is blocking
// The event is sent by value, so no need to free anything
Event wait_for_event(void) {
Event translate_event(xcb_generic_event_t *ev) {
Event ret = {0};
xcb_flush(conn);
xcb_generic_event_t *ev;
ev = xcb_wait_for_event(conn);
if (!ev)
errx(1, "xcb connection broken");