From ed6fa4e04c7d041d09736ee8b5d5ba3b3930ae9d Mon Sep 17 00:00:00 2001 From: speediegq Date: Sat, 3 Sep 2022 16:46:19 +0200 Subject: [PATCH] Add mouse toggle for toggle.h --- mouse.h | 2 ++ options.h | 2 +- speedwm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- toggle.h | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/mouse.h b/mouse.h index 0b2a5fb..31fe54f 100644 --- a/mouse.h +++ b/mouse.h @@ -3,6 +3,8 @@ * This header contains mouse binds. * Change them, or remove them if you prefer. You can also add more if you want. * Once you're done with your edits, run 'make clean install'. + * + * To disable all mouse binds, edit toggle.h. */ /* Actions when the mouse clicks a part of the screen */ diff --git a/options.h b/options.h index 4bbd198..e26b085 100644 --- a/options.h +++ b/options.h @@ -42,7 +42,7 @@ /* Software options * Note that any software named "speedwm-*" is bundled with this build and does not need to be replaced unless you want to. */ -#define TERMINAL "st -e " /* Terminal to use */ +#define TERMINAL "tabbed -r 2 st -w '' -e " /* Terminal to use */ #define BROWSER "firefox" /* Web browser to use */ #define SYSTEMSTAT "htop" /* System stat viewer to use */ #define RSS "newsboat" /* RSS reader to use */ diff --git a/speedwm.c b/speedwm.c index d2a3af1..082771e 100644 --- a/speedwm.c +++ b/speedwm.c @@ -280,7 +280,9 @@ static void attachbelow(Client *c); static void attachbottom(Client *c); static void attachtop(Client *c); static void attachstack(Client *c); +#if USEMOUSE static void buttonpress(XEvent *e); +#endif static void checkotherwm(void); static void cleanup(void); static void cleanupmon(Monitor *mon); @@ -305,7 +307,9 @@ static void drawbar(Monitor *m); static void drawbars(void); static void drawroundedcorners(Client *c); static int drawstatusbar(Monitor *m, int bh, char* text); +#if USEMOUSE static void enternotify(XEvent *e); +#endif static void expose(XEvent *e); static void focus(Client *c); static void focusin(XEvent *e); @@ -329,7 +333,9 @@ static void keypress(XEvent *e); static int fake_signal(void); static void killclient(const Arg *arg); static void killunsel(const Arg *arg); +#if USEMOUSE static void layoutmenu(const Arg *arg); +#endif static void manage(Window w, XWindowAttributes *wa); static void managealtbar(Window win, XWindowAttributes *wa); static void managetray(Window win, XWindowAttributes *wa); @@ -337,11 +343,15 @@ static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); +#if USEMOUSE static void movemouse(const Arg *arg); static void moveorplace(const Arg *arg); +#endif static Client *nexttagged(Client *c); static Client *nexttiled(Client *c); +#if USEMOUSE static void placemouse(const Arg *arg); +#endif static void opacity(Client *c, double opacity); static void pop(Client *); static void propertynotify(XEvent *e); @@ -352,7 +362,9 @@ static void resetlayout(const Arg *arg); static void reorganizetags(const Arg *arg); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); +#if USEMOUSE static void resizemouse(const Arg *arg); +#endif static void restack(Monitor *m); static void run(void); static void scantray(void); @@ -376,7 +388,9 @@ static void incrogaps(const Arg *arg); static void togglegaps(const Arg *arg); static void defaultgaps(const Arg *arg); static void setlayout(const Arg *arg); +#if USEMOUSE static void dragcfact(const Arg *arg); +#endif #if USEIPC static void setlayoutsafe(const Arg *arg); #endif @@ -410,7 +424,9 @@ static void togglefloating(const Arg *arg); static void toggleopacity(const Arg *arg); static void togglefullscr(const Arg *arg); static void freeicon(Client *c); +#if USEMOUSE static void togglewin(const Arg *arg); +#endif static void unfocus(Client *c, int setfocus); static void unmanage(Client *c, int destroyed); static void unmapnotify(XEvent *e); @@ -421,7 +437,9 @@ static void updateclientlist(void); static int updategeom(void); static void updatemotifhints(Client *c); static void updatenumlockmask(void); +#if USEMOUSE static void resizemouse(const Arg *arg); +#endif static void updatesizehints(Client *c); static void updatestatus(void); static void updaterules(Client *c); @@ -452,12 +470,16 @@ static pid_t winpid(Window w); /* variables */ static const char broken[] = "speedwm"; +#if USEMOUSE static const char *layoutmenu_cmd = "speedwm-utils -layout"; +#endif static char stext[1024]; static char rawstext[1024]; static int statusw; +#if USEMOUSE static int statuscmdn; static char lastbutton[] = "-"; +#endif static int screen; static int tw, sh; /* X display screen geometry width, height */ static int bh, blw = 0; /* bar geometry */ @@ -468,12 +490,16 @@ static int sp; /* side padding for bar */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { + #if USEMOUSE [ButtonPress] = buttonpress, + #endif [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, [ConfigureNotify] = configurenotify, [DestroyNotify] = destroynotify, + #if USEMOUSE [EnterNotify] = enternotify, + #endif [Expose] = expose, [FocusIn] = focusin, [KeyPress] = keypress, @@ -537,9 +563,10 @@ static xcb_connection_t *xcon; #include "toggle/ipc-yajl.c" #endif +#if USEMOUSE static const char *statuscmd[] = { shell, "-c", NULL, NULL }; - #include "mouse.h" /* Include mouse support */ +#endif char *get_speedwm_path(){ struct stat s; @@ -910,6 +937,7 @@ unswallow(Client *c) arrange(c->mon); } +#if USEMOUSE void buttonpress(XEvent *e) { @@ -1002,6 +1030,7 @@ buttonpress(XEvent *e) && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); } +#endif void @@ -1351,6 +1380,7 @@ destroynotify(XEvent *e) unmanagetray(ev->window); } +#if USEMOUSE void layoutmenu(const Arg *arg) { FILE *p; @@ -1364,6 +1394,7 @@ layoutmenu(const Arg *arg) { i = atoi(c); setlayout(&((Arg) {.v = &layouts[i]})); } +#endif void detach(Client *c) @@ -1427,6 +1458,7 @@ dirtomon(int dir) return m; } +#if USEMOUSE void dragcfact(const Arg *arg) { @@ -1495,6 +1527,7 @@ dragcfact(const Arg *arg) XUngrabPointer(dpy, CurrentTime); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } +#endif Bool isHexDigit(char digit) { @@ -1785,6 +1818,7 @@ drawbars(void) drawbar(m); } +#if USEMOUSE void enternotify(XEvent *e) { @@ -1805,6 +1839,7 @@ enternotify(XEvent *e) focus(c); } } +#endif void expose(XEvent *e) @@ -2071,12 +2106,15 @@ grabbuttons(Client *c, int focused) { updatenumlockmask(); { + #if USEMOUSE unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; + #endif XUngrabButton(dpy, AnyButton, AnyModifier, c->win); if (!focused) XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, GrabModeSync, GrabModeSync, None, None); + #if USEMOUSE for (i = 0; i < LENGTH(buttons); i++) if (buttons[i].click == ClkClientWin) for (j = 0; j < LENGTH(modifiers); j++) @@ -2084,6 +2122,7 @@ grabbuttons(Client *c, int focused) buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + #endif } } @@ -2342,6 +2381,7 @@ showhide(Client *c) } } +#if USEMOUSE void togglewin(const Arg *arg) { @@ -2358,6 +2398,7 @@ togglewin(const Arg *arg) restack(selmon); } } +#endif void togglegaps(const Arg *arg) @@ -2889,6 +2930,7 @@ nexttagged(Client *c) { return walked; } +#if USEMOUSE void moveorplace(const Arg *arg) { if ((!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating))) @@ -3043,6 +3085,7 @@ resizemouse(const Arg *arg) focus(NULL); } } +#endif Client * nexttiled(Client *c) @@ -4147,6 +4190,7 @@ spawn(const Arg *arg) if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); + #if USEMOUSE if (arg->v == statuscmd) { for (int i = 0; i < LENGTH(statuscmds); i++) { if (statuscmdn == statuscmds[i].id) { @@ -4158,6 +4202,7 @@ spawn(const Arg *arg) if (!statuscmd[2]) exit(EXIT_SUCCESS); } + #endif setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); @@ -4861,6 +4906,10 @@ view(const Arg *arg) int i; unsigned int tmptag; + #if USEMOUSE + selmon->mouseactivated = 1; + #endif + /* fix: tag preview gets captured in the next tag preview if the user switched tag while a preview is showing */ if (selmon->previewshow && !selmon->mouseactivated) return; diff --git a/toggle.h b/toggle.h index 348cdaf..6aa5af8 100644 --- a/toggle.h +++ b/toggle.h @@ -3,3 +3,4 @@ */ #define USEIPC 1 /* Whether or not to use IPC. If you set this to 1, set USEIPC to true in config.mk and comment the YAJLLIBS and YAJLINC lines in config.mk. Not compatible with BSDs so for those, set this to 0. */ #define USEALPHA 1 /* Whether or not to use transparency for the bar */ +#define USEMOUSE 1 /* Whether or not to use mouse binds */