From 3036894841fce9b73e6b34779eeabbe326e19302 Mon Sep 17 00:00:00 2001 From: uint23 Date: Sun, 20 Apr 2025 06:13:41 +0100 Subject: fullscr support + readme glowup + makefile glowup gaaaaashhh --- src/config | 4 +++- src/defs.h | 7 ++++++- src/sxwm.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/config b/src/config index 2c2fb8d..97e15bc 100644 --- a/src/config +++ b/src/config @@ -98,7 +98,6 @@ CMD(terminal, "st"); CMD(browser, "firefox"); - /* * ———————————————< Bindings >————————————————* * @@ -179,6 +178,8 @@ static const Binding binds[] = CALL(MOD, space, toggle_floating), CALL(MOD|SHIFT, space, toggle_floating_global), + CALL(MOD|SHIFT, f, toggle_fullscreen), + /*—————< Here are your executable functions >—————*/ BIND(MOD, Return, terminal), @@ -212,4 +213,5 @@ static const Binding binds[] = CALL(MOD, 9, change_ws9), CALL(MOD|SHIFT, 9, moveto_ws9), + }; diff --git a/src/defs.h b/src/defs.h index f8de140..58c2360 100644 --- a/src/defs.h +++ b/src/defs.h @@ -3,9 +3,12 @@ #ifndef DEFS_H #define DEFS_H -#include #include +#define uint unsigned int +#define ulong unsigned long +#define u_char unsigned char + #define SXWM_VERSION "sxwm ver. 0.1.5" #define SXWM_AUTHOR "(C) Abhinav Prasai 2025" #define SXWM_LICINFO "See LICENSE for more info" @@ -83,7 +86,9 @@ typedef struct { typedef struct Client{ Window win; uint x, y, h, w; + uint orig_x, orig_y, orig_w, orig_h; Bool floating; + Bool fullscreen; struct Client *next; } Client; diff --git a/src/sxwm.c b/src/sxwm.c index 98d7b4a..f89833a 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -59,6 +59,7 @@ static void spawn(const char **cmd); static void tile(void); static void toggle_floating(void); static void toggle_floating_global(void); +static void toggle_fullscreen(void); static void update_borders(void); static int xerr(Display *dpy, XErrorEvent *ee); static void xev_case(XEvent *xev); @@ -122,7 +123,8 @@ add_client(Window w) c->y = wa.y; c->w = wa.width; c->h = wa.height; - c->floating = 0; + c->floating = False; + c->fullscreen = False; if (global_floating) { XSetWindowBorder(dpy, c->win, border_foc_col); @@ -504,6 +506,12 @@ move_to_workspace(uint ws) if (!focused || ws >= NUM_WORKSPACES || ws == current_ws) return; + if (focused->fullscreen) { + focused->fullscreen = False; + XMoveResizeWindow(dpy, focused->win, focused->orig_x, focused->orig_y, focused->orig_w, focused->orig_h); + XSetWindowBorderWidth(dpy, focused->win, BORDER_WIDTH); + } + /* remove from current list */ Client **pp = &workspaces[current_ws]; while (*pp && *pp != focused) pp = &(*pp)->next; @@ -702,9 +710,13 @@ tile(void) { uint total_windows = 0; Client *head = workspaces[current_ws]; - for (Client *c = head; c; c = c->next) + for (Client *c = head; c; c = c->next) { + if (c->fullscreen) + return; + if (!c->floating) ++total_windows; + } if (total_windows == 0) return; @@ -777,7 +789,13 @@ static void toggle_floating(void) { if (!focused) return; + focused->floating = !focused->floating; + if (focused->fullscreen) { + focused->fullscreen = False; + tile(); + XSetWindowBorderWidth(dpy, focused->win, BORDER_WIDTH); + } if (focused->floating) { XWindowAttributes wa; @@ -846,6 +864,41 @@ toggle_floating_global(void) update_borders(); } +static void +toggle_fullscreen(void) +{ + if (!focused) + return; + + if (focused->floating) + focused->floating = False; + + focused->fullscreen = !focused->fullscreen; + + if (focused->fullscreen) { + XWindowAttributes wa; + XGetWindowAttributes(dpy, focused->win, &wa); + focused->orig_x = wa.x; + focused->orig_y = wa.y; + focused->orig_w = wa.width; + focused->orig_h = wa.height; + + uint fs_x = 0; + uint fs_y = 0; + uint fs_w = scr_width; + uint fs_h = scr_height; + + XSetWindowBorderWidth(dpy, focused->win, 0); + XMoveResizeWindow(dpy, focused->win, fs_x, fs_y, fs_w, fs_h); + XRaiseWindow(dpy, focused->win); // Ensure it's on top + } else { + XMoveResizeWindow(dpy, focused->win, focused->orig_x, focused->orig_y, focused->orig_w, focused->orig_h); + XSetWindowBorderWidth(dpy, focused->win, BORDER_WIDTH); + tile(); + update_borders(); + } +} + static void update_borders(void) { @@ -889,6 +942,7 @@ change_workspace(uint ws) static int xerr(Display *dpy, XErrorEvent *ee) { + /* TODO MAKE IT BETTER */ if (ee->error_code == BadWindow || ee->error_code == BadDrawable || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) -- cgit v1.2.3