Fix: Tag previews don't work well with leftlayout, tag previews don't

disappear when the mouse leaves the bar
This commit is contained in:
speediegq 2022-10-03 21:57:15 +02:00
parent db1e9a9556
commit 76e830515c
3 changed files with 91 additions and 42 deletions

View file

@ -16,7 +16,7 @@
# Compiling with -Ofast. If you're having issues (such as dwm crashing, change it to -O2. (That's not a zero)
# Using -O2 is not recommended due to the usage of Imlib2.
# If these features are used, they will be slow with the use of -O2.
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Ofast ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Wno-unused-variable -Ofast -march=native ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
# Compiler and linker.

129
speedwm.c
View file

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details.
*/
/* See LICENSE file for copyright and license details. */
#include <assert.h>
#include <errno.h>
#include <locale.h>
@ -238,9 +237,6 @@ struct Monitor {
int showbar;
int barposition;
int hidsel;
#if USETAGPREVIEWFIX
int mouseactivated;
#endif
int isreset;
Client *clients;
Client *sel;
@ -1096,9 +1092,6 @@ buttonpress(XEvent *e)
} while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags) && !hidetags) {
#if USETAGPREVIEWFIX
selmon->mouseactivated = 1;
#endif
click = ClkTagBar;
if ( ev->button == Button4 || ev->button == Button5 ) {
arg.ui = selmon->tagset[selmon->seltags];
@ -1111,6 +1104,14 @@ buttonpress(XEvent *e)
}
} else
arg.ui = 1 << i;
#if USETAGPREVIEW
if (selmon->previewshow) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
#endif
} else if (ev->x < x + TEXTW(selmon->ltsymbol) && !layoutposition && !selmon->isreset) // right layout
click = ClkLtSymbol; // right layout
#if USESYSTRAY
@ -1141,7 +1142,7 @@ buttonpress(XEvent *e)
}
} else {
if (!layoutposition) {
x += TEXTW(m->ltsymbol);; // Left layout does not need this
x += TEXTW(m->ltsymbol); // Left layout does not need this
}
// Don't click if title is hidden
@ -1935,7 +1936,7 @@ if(showsystray && m == systraytomon(m) && !systrayonleft)
resizebarwin(m);
#endif
// for statuscmd
/* for statuscmd */
for (text = s = stext; *s; s++) {
if ((unsigned char)(*s) < ' ') {
ch = *s;
@ -3068,6 +3069,7 @@ maprequest(XEvent *e)
manage(ev->window, &wa);
}
/*
void
motionnotify(XEvent *e)
{
@ -3079,6 +3081,7 @@ motionnotify(XEvent *e)
XMotionEvent *ev = &e->xmotion;
unsigned int i, x = 0, occ = 0;
#if USETAGPREVIEW
if (ev->window == selmon->barwin) {
i = x = 0;
@ -3088,35 +3091,36 @@ motionnotify(XEvent *e)
else
occ |= c->tags;
if (layoutposition)
x += TEXTW(m->ltsymbol);
x += TEXTW(m->ltsymbol) + 20;
do {
if (!(occ & 1 << i || selmon->tagset[selmon->seltags] & 1 << i) && hideemptytags)
continue;
x += TEXTW(occ & 1 << i ? usedtags[i] : tags[i]);
x += TEXTW(tags[i]);
} while (ev->x >= x && ++i < (LENGTH(tags)));
#if USETAGPREVIEW
if (mousepreview && !hidetags) {
if (i < LENGTH(tags)) {
if ((i + 1) != selmon->previewshow && !(selmon->tagset[selmon->seltags] & 1 << i)) {
if (mousepreview && !hidetags) {
if (i < LENGTH(tags)) {
if (selmon->previewshow != (i + 1) && !(selmon->seltags & 1 << i)) {
selmon->previewshow = i + 1;
showtagpreview(i);
} else if (selmon->tagset[selmon->seltags] & 1 << i) {
} else if (selmon->seltags & 1 << i) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
XUnmapWindow(dpy, selmon->tagwin);
}
} else if (selmon->previewshow) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
} else if (ev->window == selmon->tagwin) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
} else if (selmon->previewshow) {
showtagpreview(0);
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
}
#endif
}
if (ev->window != root)
return;
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
@ -3126,6 +3130,69 @@ motionnotify(XEvent *e)
}
mon = m;
}
*/
void
motionnotify(XEvent *e)
{
static Monitor *mon = NULL;
Monitor *m;
m = 0;
Client *sel;
XMotionEvent *ev = &e->xmotion;
Client *c;
unsigned int i, x, occ = 0, lts = 0;
#if USETAGPREVIEW
if (ev->window == selmon->barwin) {
i = x = 0;
// for leftlayout, we need to add the size of the layout indicator
if (layoutposition) {
lts = TEXTW(selmon->ltsymbol);
}
for (c = selmon->clients; c; c = c->next)
occ |= c->tags == 255 ? 0 : c->tags;
do {
if (!(occ & 1 << i || selmon->seltags & 1 << i) && hideemptytags)
continue;
x += TEXTW(tags[i]) + lts;
} while (ev->x >= x && ++i < LENGTH(tags));
if (mousepreview && !hidetags) {
if (i < LENGTH(tags)) {
if (selmon->previewshow != (i + 1)
&& !(selmon->seltags & 1 << i)) {
selmon->previewshow = i + 1;
showtagpreview(i);
} else if (selmon->seltags & 1 << i) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
} else if (selmon->previewshow) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
} else if (ev->window == selmon->tagwin) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
} else if (selmon->previewshow) {
selmon->previewshow = 0;
XUnmapWindow(dpy, selmon->tagwin);
}
} // mousepreview && !hidetags
#endif
if (ev->window != root)
return;
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
sel = selmon->sel;
selmon = m;
unfocus(sel, 1);
focus(NULL);
}
mon = m;
}
void
toggleview(const Arg *arg)
@ -5464,19 +5531,6 @@ view(const Arg *arg)
int i;
unsigned int tmptag;
#if USEMOUSE
#if USETAGPREVIEWFIX
selmon->mouseactivated = 1;
#endif
#endif
#if USETAGPREVIEWFIX
#if USETAGPREVIEW
if (selmon->previewshow && !selmon->mouseactivated)
return;
#endif
#endif
if(arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
#if USETAGPREVIEW
@ -5515,9 +5569,6 @@ view(const Arg *arg)
#if USETAGPREVIEW
XUnmapWindow(dpy, selmon->tagwin);
#endif
#if USETAGPREVIEWFIX
selmon->mouseactivated = 0;
#endif
focus(NULL);
arrange(NULL);

View file

@ -34,8 +34,6 @@ Not compatible with BSDs so for those, set this to 0. */
#define USEIMLIB2 1 /* Whether or not to use imlib2. Required by USEWINICON and USETAGPREVIEW. */
#define USEWINICON 1 /* Whether or not to use window icons. Requires imlib to be enabled in toggle.mk and it must be installed. */
#define USETAGPREVIEW 1 /* Whether or not to use tag previews. Requires imlib to be enabled in toggle.mk and it must be installed. */
#define USETAGPREVIEWFIX 0 /* Experimental fix for tag previews showing up in the tag preview when a window animations are enabled.
Using this is not recommended and if you use the mouse to switch tags, it will not work. */
/* Layouts
* If you don't use a layout, you can remove it to keep the speedwm binary small.