From 55d6921b4504bb3d4f594caf494161dae4da7436 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Fri, 5 Mar 2021 23:55:13 -0500 Subject: [PATCH] config.h, main.c, key.c, manage.c, client.c: add zoom mode (fullscreen everything); event.c, menu.c: don't leave us out of focus when deleting windows --- client.c | 11 +++++++++++ config.h | 1 + dat.h | 1 + event.c | 5 +++++ key.c | 12 ++++++++++++ main.c | 1 + manage.c | 10 ++++++++++ menu.c | 10 ++++++++-- 8 files changed, 49 insertions(+), 2 deletions(-) diff --git a/client.c b/client.c index 03435a8..594ec77 100644 --- a/client.c +++ b/client.c @@ -277,6 +277,9 @@ void dump_clients(void) { void shuffle(int up) { Client **l, *c; + static XWindowAttributes ra; + + XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); if (clients == 0 || clients->next == 0) return; @@ -297,6 +300,14 @@ void shuffle(int up) { XMapRaised(dpy, c->parent); top(c); active(c); + if (zoom) { + quickreshape( + c, + -BORDER, + -BORDER, + ra.width + 2 * BORDER, + ra.height + 2 * BORDER); + } } else { c = clients; for (l = &clients; *l; l = &(*l)->next) diff --git a/config.h b/config.h index 749ecd3..42494ef 100644 --- a/config.h +++ b/config.h @@ -60,6 +60,7 @@ #define RESIZE_KEY XK_r #define DESTROY_KEY XK_d #define STICK_KEY XK_s +#define ZOOM_KEY XK_z #define STICKYTOFRONT_KEY XK_t #define STICKYTOBACK_KEY XK_b diff --git a/dat.h b/dat.h index cd41513..fd4ea2e 100644 --- a/dat.h +++ b/dat.h @@ -157,6 +157,7 @@ extern int solidsweep; extern int numvirtuals; extern int scrolling; extern int ffm; /* focus follows mouse */ +extern int zoom; extern Atom exit_rio; extern Atom restart_rio; diff --git a/event.c b/event.c index 075c5df..6e7f6e2 100644 --- a/event.c +++ b/event.c @@ -292,18 +292,23 @@ void newwindow(XCreateWindowEvent* e) { void destroy(Window w) { int i; Client* c; + int v; curtime = CurrentTime; c = getclient(w, 0); if (c == 0) return; + v = c->virt; if (numvirtuals > 1) for (i = 0; i < numvirtuals; i++) if (currents[i] == c) currents[i] = 0; rmclient(c); + if (v == virt) { + shuffle(0); + } /* flush any errors generated by the window's sudden demise */ ignore_badwindow = 1; diff --git a/key.c b/key.c index 6b9ae27..84189ab 100644 --- a/key.c +++ b/key.c @@ -47,6 +47,7 @@ void keysetup(void) { int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY); int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); + int zcode = XKeysymToKeycode(dpy, ZOOM_KEY); int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY); int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY); #ifdef DEVEL @@ -223,6 +224,14 @@ void keysetup(void) { 0, GrabModeSync, GrabModeAsync); + XGrabKey( + dpy, + zcode, + SHORTCUTMOD, + screens[i].root, + 0, + GrabModeSync, + GrabModeAsync); XGrabKey( dpy, tabcode, @@ -271,6 +280,7 @@ void keypress(XKeyEvent* e) { int scode = XKeysymToKeycode(dpy, STICK_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); + int zcode = XKeysymToKeycode(dpy, ZOOM_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); @@ -312,6 +322,8 @@ void keypress(XKeyEvent* e) { ra.height + 2 * BORDER); else if (e->keycode == scode && (e->state & SHORTCUTMOD) == (MODBITS)) stick(current); + else if (e->keycode == zcode && (e->state & SHORTCUTMOD) == (MODBITS)) + zoom = !zoom; /* half snap */ else if (e->keycode == hcode && (e->state & SHORTCUTMOD) == (MODBITS)) diff --git a/main.c b/main.c index d17c0d9..c453ac3 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,7 @@ int solidsweep = 0; int numvirtuals = 0; int ffm = 0; int kbLaunch = 0; +int zoom = 0; Atom exit_rio; Atom restart_rio; diff --git a/manage.c b/manage.c index d710adb..1648f1e 100644 --- a/manage.c +++ b/manage.c @@ -219,6 +219,16 @@ int manage(Client* c, int mapped) { cmapfocus(current); c->init = 1; + /* If we are in zoom mode, spawn the window maximized */ + if (zoom) { + quickreshape( + c, + -BORDER, + -BORDER, + ra.width + 2 * BORDER, + ra.height + 2 * BORDER); + } + /* If the window is out of bounds of the screen, try to wrangle it */ /* If it's bigger than the screen, try to set it maximized */ diff --git a/menu.c b/menu.c index 591d337..c496941 100644 --- a/menu.c +++ b/menu.c @@ -165,7 +165,7 @@ void button(XButtonEvent* e) { case Delete: shift = 0; c = selectwin(1, &shift, s); - delete (c, shift); + delete(c, shift); break; case Hide: hide(selectwin(1, 0, s)); @@ -260,10 +260,16 @@ void move(Client* c, int but) { } void delete (Client* c, int shift) { + int v; if (c == 0) return; - if ((c->proto & Pdelete) && !shift) + v = c->virt; + if ((c->proto & Pdelete) && !shift) { sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); + if (v == virt) { + shuffle(0); + } + } else XKillClient(dpy, c->window); /* let event clean up */ }