kbgwm

sucklessy floating window manager
git clone https://git.neuralcrash.com/kbgwm.git
Log | Files | Refs | README | LICENSE

commit 70fd71e5c3846c61946e1364eea6add61787f4b5
parent 975734e2da35f39fe023f02258f718c48b8a4986
Author: Kebigon <git@kebigon.xyz>
Date:   Tue, 21 Jul 2020 20:47:54 +0900

Add possibility to maximize/unmaximize a client

Diffstat:
Mconfig.h | 17+++++++++--------
Mkbgwm.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mtypes.h | 1+
3 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/config.h b/config.h @@ -21,14 +21,15 @@ static const char* menucmd[] = { "dmenu_run", NULL }; static Key keys[] = { - { MODKEY, XK_Return, start, { .cmd = termcmd } }, - { MODKEY, XK_p, start, { .cmd = menucmd } }, - { MODKEY, XK_Page_Up, workspace_previous, { 0 } }, - { MODKEY, XK_Page_Down, workspace_next, { 0 } }, - { MODKEY | SHIFT, XK_Tab, focus_next, { .b = true } }, - { MODKEY, XK_Tab, focus_next, { .b = false } }, - { MODKEY, XK_q, client_kill, { 0 } }, - { MODKEY | SHIFT, XK_q, quit, { 0 } }, + { MODKEY, XK_Return, start, { .cmd = termcmd } }, + { MODKEY, XK_p, start, { .cmd = menucmd } }, + { MODKEY, XK_Page_Up, workspace_previous, { 0 } }, + { MODKEY, XK_Page_Down, workspace_next, { 0 } }, + { MODKEY | SHIFT, XK_Tab, focus_next, { .b = true } }, + { MODKEY, XK_Tab, focus_next, { .b = false } }, + { MODKEY, XK_q, client_kill, { 0 } }, + { MODKEY | SHIFT, XK_q, quit, { 0 } }, + { MODKEY, XK_x, client_toggle_maximize, { 0 } }, WORKSPACEKEYS(XK_Home, 0) WORKSPACEKEYS(XK_1, 0) WORKSPACEKEYS(XK_2, 1) diff --git a/kbgwm.c b/kbgwm.c @@ -26,6 +26,9 @@ static void client_kill(const Arg*); static void client_create(xcb_window_t); static void client_sanitize_position(client*); static void client_sanitize_dimensions(client*); +static void client_toggle_maximize(const Arg*); +static void client_maximize(client*); +static void client_unmaximize(client*); static void focus_apply(); static void focus_next(const Arg*); static void focus_unfocus(); @@ -250,6 +253,7 @@ void client_create(xcb_window_t id) new_client->min_height = hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE ? hints.min_height : 0; new_client->max_width = hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE ? hints.max_width : 0xFFFF; new_client->max_height = hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE ? hints.max_height : 0xFFFF; + new_client->maximized = false; client_sanitize_dimensions(new_client); @@ -379,6 +383,44 @@ void client_kill(__attribute__((unused))const Arg* arg) xcb_flush(c); } +void client_toggle_maximize(__attribute__((unused))const Arg* arg) +{ + // No client are focused + if (workspaces[current_workspace] == NULL) + return; // Nothing to be done + + client* client = workspaces[current_workspace]; + + if (client->maximized) + client_unmaximize(client); + else + client_maximize(client); + + xcb_flush(c); +} + +void client_maximize(client* client) +{ + assert(client != NULL); + assert(!client->maximized); + + client->maximized = true; + + uint32_t values[] = { 0, 0, screen->width_in_pixels - BORDER_WIDTH_X2, screen->height_in_pixels - BORDER_WIDTH_X2 }; + xcb_configure_window(c, focused_client->id, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); +} + +void client_unmaximize(client* client) +{ + assert(client != NULL); + assert(client->maximized); + + client->maximized = false; + + uint32_t values[] = { client->x, client->y, client->width, client->height }; + xcb_configure_window(c, focused_client->id, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); +} + /* * Focus */ @@ -524,13 +566,18 @@ void handle_mapping_notify(xcb_mapping_notify_event_t* event) void handle_motion_notify(xcb_motion_notify_event_t* event) { + client* client = workspaces[current_workspace]; + assert(moving || resizing); - assert(focused_client != NULL); - assert(focused_client->id != root); + assert(client != NULL); + assert(client->id != root); printf("handle_motionnotify: root_x=%d root_y=%d event_x=%d event_y=%d\n", event->root_x, event->root_y, event->event_x, event->event_y); + if (client->maximized) + client_unmaximize(client); + int16_t diff_x = event->root_x - previous_x; int16_t diff_y = event->root_y - previous_y; previous_x = event->root_x; @@ -538,23 +585,21 @@ void handle_motion_notify(xcb_motion_notify_event_t* event) if (moving) { - focused_client->x += diff_x; - focused_client->y += diff_y; - client_sanitize_position(focused_client); + client->x += diff_x; + client->y += diff_y; + client_sanitize_position(client); - uint32_t values[2] = - { focused_client->x, focused_client->y}; - xcb_configure_window(c, focused_client->id, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values); + uint32_t values[2] = { client->x, client->y }; + xcb_configure_window(c, client->id, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values); } else if (resizing) { - focused_client->width += diff_x; - focused_client->height += diff_y; - client_sanitize_dimensions(focused_client); + client->width += diff_x; + client->height += diff_y; + client_sanitize_dimensions(client); - uint32_t values[2] = - { focused_client->width, focused_client->height}; - xcb_configure_window(c, focused_client->id, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); + uint32_t values[2] = { client->width, client->height }; + xcb_configure_window(c, client->id, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); } xcb_flush(c); diff --git a/types.h b/types.h @@ -34,6 +34,7 @@ struct client_t uint16_t width, height; int32_t min_width, min_height; int32_t max_width, max_height; + bool maximized; client* previous; client* next; };