diff options
| author | Stein Gunnar Bakkeby <[email protected]> | 2022-07-05 14:55:42 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-07-05 14:55:42 +0200 |
| commit | 5f7df0b0dc78ae00f21d5bbe892456c450506b9b (patch) | |
| tree | 73610f0475c0e5b7ef5a2017e11813908e769fcd /patch | |
| parent | 20692bea017353bcaf069625bcf3bda6eed4ad51 (diff) | |
| download | dwm-flexipatch-5f7df0b0dc78ae00f21d5bbe892456c450506b9b.tar.gz dwm-flexipatch-5f7df0b0dc78ae00f21d5bbe892456c450506b9b.zip | |
Adding tagpreview patch (#271)
Diffstat (limited to 'patch')
| -rw-r--r-- | patch/bar.c | 39 | ||||
| -rw-r--r-- | patch/bar.h | 2 | ||||
| -rw-r--r-- | patch/bar_tagpreview.c | 95 | ||||
| -rw-r--r-- | patch/bar_tagpreview.h | 4 | ||||
| -rw-r--r-- | patch/bar_tags.c | 53 | ||||
| -rw-r--r-- | patch/bar_tags.h | 2 | ||||
| -rw-r--r-- | patch/include.c | 4 | ||||
| -rw-r--r-- | patch/include.h | 4 |
8 files changed, 202 insertions, 1 deletions
diff --git a/patch/bar.c b/patch/bar.c new file mode 100644 index 0000000..65e1a69 --- /dev/null +++ b/patch/bar.c @@ -0,0 +1,39 @@ +void +barhover(XEvent *e, Bar *bar) +{ + const BarRule *br; + Monitor *m = bar->mon; + XMotionEvent *ev = &e->xmotion; + BarArg barg = { 0, 0, 0, 0 }; + int r; + + for (r = 0; r < LENGTH(barrules); r++) { + br = &barrules[r]; + if (br->bar != bar->idx || (br->monitor == 'A' && m != selmon) || br->hoverfunc == NULL) + continue; + if (br->monitor != 'A' && br->monitor != -1 && br->monitor != bar->mon->num) + continue; + if (bar->x[r] > ev->x || ev->x > bar->x[r] + bar->w[r]) + continue; + + barg.x = ev->x - bar->x[r]; + barg.y = ev->y - bar->borderpx; + barg.w = bar->w[r]; + barg.h = bar->bh - 2 * bar->borderpx; + + br->hoverfunc(bar, &barg, ev); + break; + } +} + +Bar * +wintobar(Window win) +{ + Monitor *m; + Bar *bar; + for (m = mons; m; m = m->next) + for (bar = m->bar; bar; bar = bar->next) + if (bar->win == win) + return bar; + return NULL; +} diff --git a/patch/bar.h b/patch/bar.h new file mode 100644 index 0000000..3e006dc --- /dev/null +++ b/patch/bar.h @@ -0,0 +1,2 @@ +static void barhover(XEvent *e, Bar *bar); +static Bar *wintobar(Window win); diff --git a/patch/bar_tagpreview.c b/patch/bar_tagpreview.c new file mode 100644 index 0000000..c92d05f --- /dev/null +++ b/patch/bar_tagpreview.c @@ -0,0 +1,95 @@ +#include <Imlib2.h> + +void +showtagpreview(int tag, int x, int y) +{ + if (selmon->tagmap[tag]) { + XSetWindowBackgroundPixmap(dpy, selmon->tagwin, selmon->tagmap[tag]); + XCopyArea(dpy, selmon->tagmap[tag], selmon->tagwin, drw->gc, 0, 0, selmon->mw / scalepreview, selmon->mh / scalepreview, 0, 0); + XMoveWindow(dpy, selmon->tagwin, x, y); + XSync(dpy, False); + XMapWindow(dpy, selmon->tagwin); + } else + XUnmapWindow(dpy, selmon->tagwin); +} + +void +hidetagpreview(Monitor *m) +{ + m->previewshow = 0; + XUnmapWindow(dpy, m->tagwin); +} + +void +tagpreviewswitchtag(void) +{ + int i; + unsigned int occ = 0; + Client *c; + Imlib_Image image; + + for (c = selmon->clients; c; c = c->next) + occ |= c->tags; + for (i = 0; i < NUMTAGS; i++) { + if (selmon->tagset[selmon->seltags] & 1 << i) { + if (selmon->tagmap[i] != 0) { + XFreePixmap(dpy, selmon->tagmap[i]); + selmon->tagmap[i] = 0; + } + if (occ & 1 << i) { + image = imlib_create_image(sw, sh); + imlib_context_set_image(image); + imlib_context_set_display(dpy); + #if BAR_ALPHA_PATCH + imlib_image_set_has_alpha(1); + imlib_context_set_blend(0); + imlib_context_set_visual(visual); + #else + imlib_context_set_visual(DefaultVisual(dpy, screen)); + #endif // BAR_ALPHA_PATCH + imlib_context_set_drawable(root); + imlib_copy_drawable_to_image(0, selmon->mx, selmon->my, selmon->mw ,selmon->mh, 0, 0, 1); + #if BAR_ALPHA_PATCH + selmon->tagmap[i] = XCreatePixmap(dpy, selmon->tagwin, selmon->mw / scalepreview, selmon->mh / scalepreview, depth); + #else + selmon->tagmap[i] = XCreatePixmap(dpy, selmon->tagwin, selmon->mw / scalepreview, selmon->mh / scalepreview, DefaultDepth(dpy, screen)); + #endif // BAR_ALPHA_PATCH + imlib_context_set_drawable(selmon->tagmap[i]); + imlib_render_image_part_on_drawable_at_size(0, 0, selmon->mw, selmon->mh, 0, 0, selmon->mw / scalepreview, selmon->mh / scalepreview); + imlib_free_image(); + } + } + } +} + +void +updatepreview(void) +{ + Monitor *m; + + XSetWindowAttributes wa = { + .override_redirect = True, + #if BAR_ALPHA_PATCH + .background_pixel = 0, + .border_pixel = 0, + .colormap = cmap, + #else + .background_pixmap = ParentRelative, + #endif // BAR_ALPHA_PATCH + .event_mask = ButtonPressMask|ExposureMask + }; + for (m = mons; m; m = m->next) { + m->tagwin = XCreateWindow(dpy, root, m->wx, m->bar->by + bh, m->mw / 4, m->mh / 4, 0, + #if BAR_ALPHA_PATCH + depth, CopyFromParent, visual, + CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa + #else + DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa + #endif // BAR_ALPHA_PATCH + ); + XDefineCursor(dpy, m->tagwin, cursor[CurNormal]->cursor); + XMapRaised(dpy, m->tagwin); + XUnmapWindow(dpy, m->tagwin); + } +} diff --git a/patch/bar_tagpreview.h b/patch/bar_tagpreview.h new file mode 100644 index 0000000..8129187 --- /dev/null +++ b/patch/bar_tagpreview.h @@ -0,0 +1,4 @@ +static void showtagpreview(int tag, int x, int y); +static void hidetagpreview(Monitor *m); +static void tagpreviewswitchtag(void); +static void updatepreview(void); diff --git a/patch/bar_tags.c b/patch/bar_tags.c index 8b9092d..6a420d0 100644 --- a/patch/bar_tags.c +++ b/patch/bar_tags.c @@ -91,3 +91,56 @@ click_tags(Bar *bar, Arg *arg, BarArg *a) return ClkTagBar; } +int +hover_tags(Bar *bar, BarArg *a, XMotionEvent *ev) +{ + #if BAR_TAGPREVIEW_PATCH + int i = 0, x = lrpad / 2; + int px, py; + Monitor *m = bar->mon; + #if VANITYGAPS_PATCH + int ov = gappov; + int oh = gappoh; + #else + int ov = 0; + int oh = 0; + #endif // VANITYGAPS_PATCH + + #if BAR_HIDEVACANTTAGS_PATCH + Client *c; + unsigned int occ = 0; + for (c = bar->mon->clients; c; c = c->next) + occ |= c->tags == 255 ? 0 : c->tags; + #endif // BAR_HIDEVACANTTAGS_PATCH + + do { + #if BAR_HIDEVACANTTAGS_PATCH + if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i)) + continue; + #endif // BAR_HIDEVACANTTAGS_PATCH + x += TEXTW(tagicon(bar->mon, i)); + } while (a->x >= x && ++i < NUMTAGS); + + if (i < NUMTAGS) { + if ((i + 1) != selmon->previewshow && !(selmon->tagset[selmon->seltags] & 1 << i)) { + if (bar->by > m->my + m->mh / 2) // bottom bar + py = bar->by - m->mh / scalepreview - oh; + else // top bar + py = bar->by + bar->bh + oh; + px = bar->bx + ev->x - m->mw / scalepreview / 2; + if (px + m->mw / scalepreview > m->mx + m->mw) + px = m->wx + m->ww - m->mw / scalepreview - ov; + else if (px < bar->bx) + px = m->wx + ov; + selmon->previewshow = i + 1; + showtagpreview(i, px, py); + } else if (selmon->tagset[selmon->seltags] & 1 << i) { + hidetagpreview(selmon); + } + } else if (selmon->previewshow != 0) { + hidetagpreview(selmon); + } + #endif // BAR_TAGPREVIEW_PATCH + + return 1; +} diff --git a/patch/bar_tags.h b/patch/bar_tags.h index 9261261..70040d2 100644 --- a/patch/bar_tags.h +++ b/patch/bar_tags.h @@ -1,4 +1,4 @@ static int width_tags(Bar *bar, BarArg *a); static int draw_tags(Bar *bar, BarArg *a); static int click_tags(Bar *bar, Arg *arg, BarArg *a); - +static int hover_tags(Bar *bar, BarArg *a, XMotionEvent *ev); diff --git a/patch/include.c b/patch/include.c index 6f9768a..33232cf 100644 --- a/patch/include.c +++ b/patch/include.c @@ -1,6 +1,7 @@ /* Bar functionality */ #include "bar_indicators.c" #include "bar_tagicons.c" +#include "bar.c" #if BAR_ALPHA_PATCH #include "bar_alpha.c" @@ -50,6 +51,9 @@ #if BAR_TABGROUPS_PATCH #include "bar_tabgroups.c" #endif +#if BAR_TAGPREVIEW_PATCH +#include "bar_tagpreview.c" +#endif #if BAR_TAGS_PATCH #include "bar_tags.c" #endif diff --git a/patch/include.h b/patch/include.h index 2ad61df..2a78292 100644 --- a/patch/include.h +++ b/patch/include.h @@ -1,6 +1,7 @@ /* Bar functionality */ #include "bar_indicators.h" #include "bar_tagicons.h" +#include "bar.h" #if BAR_ALPHA_PATCH #include "bar_alpha.h" @@ -59,6 +60,9 @@ #if BAR_TAGLABELS_PATCH #include "bar_taglabels.h" #endif +#if BAR_TAGPREVIEW_PATCH +#include "bar_tagpreview.h" +#endif #if BAR_TAGGRID_PATCH #include "bar_taggrid.h" #endif |
