Browse Source

scale the tag preview!

siduck76 3 years ago
parent
commit
75168cc5d5
4 changed files with 92 additions and 72 deletions
  1. 2 3
      chadwm/config.def.h
  2. 59 42
      chadwm/dwm.c
  3. 31 0
      chadwm/functions.h
  4. 0 27
      chadwm/vanitygaps.c

+ 2 - 3
chadwm/config.def.h

@@ -26,6 +26,7 @@ static const int vertpadbar         = 11;
 static const int vertpadtab         = 33;
 static const int horizpadtabi       = 15;
 static const int horizpadtabo       = 15;
+static const int scalepreview       = 4;
 static const char *fonts[]          = { "JetBrainsMono Nerd Font:style:medium:size=10",
                                         "Material Design Icons-Regular:size=10",
                                       };
@@ -94,9 +95,7 @@ static const int resizehints = 0;    /* 1 means respect size hints in tiled resi
 static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
 
 #define FORCE_VSPLIT 1  /* nrowgrid layout: force two clients to always split vertically */
-#include "vanitygaps.c"
-#include "movestack.c"
-#include "tatami.c"
+#include "functions.h"
 
 static const Layout layouts[] = {
     /* symbol     arrange function */

+ 59 - 42
chadwm/dwm.c

@@ -61,6 +61,7 @@
 #define TAGMASK ((1 << LENGTH(tags)) - 1)
 #define TAGSLENGTH              (LENGTH(tags))
 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define MAXTABS 50
 
 #define SYSTEM_TRAY_REQUEST_DOCK 0
 
@@ -191,44 +192,6 @@ typedef struct {
   void (*arrange)(Monitor *);
 } Layout;
 
-#define MAXTABS 50
-
-struct Monitor {
-  char ltsymbol[16];
-  float mfact;
-  int nmaster;
-  int num;
-  int by;             /* bar geometry */
-  int ty;             /* tab bar geometry */
-  int mx, my, mw, mh; /* screen size */
-  int wx, wy, ww, wh; /* window area  */
-  int gappih;         /* horizontal gap between windows */
-  int gappiv;         /* vertical gap between windows */
-  int gappoh;         /* horizontal outer gaps */
-  int gappov;         /* vertical outer gaps */
-  unsigned int borderpx;
-  unsigned int seltags;
-  unsigned int sellt;
-  unsigned int tagset[2];
-  unsigned int colorfultag;
-  int showbar, showtab;
-  int topbar, toptab;
-  Client *clients;
-  Client *sel;
-  Client *stack;
-  Monitor *next;
-  Window barwin;
-  Window tabwin;
-  Window tagwin;
-  Pixmap tagmap;
-  Imlib_Image tag_images[9];
-  int previewshow;
-  int ntabs;
-  int tab_widths[MAXTABS];
-  int tab_btn_w[3];
-  const Layout *lt[2];
-};
-
 typedef struct {
   const char *class;
   const char *instance;
@@ -411,6 +374,46 @@ static Window root, wmcheckwin;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
+struct Monitor {
+  char ltsymbol[16];
+  float mfact;
+  int nmaster;
+  int num;
+  int by;             /* bar geometry */
+  int ty;             /* tab bar geometry */
+  int mx, my, mw, mh; /* screen size */
+  int wx, wy, ww, wh; /* window area  */
+  int gappih;         /* horizontal gap between windows */
+  int gappiv;         /* vertical gap between windows */
+  int gappoh;         /* horizontal outer gaps */
+  int gappov;         /* vertical outer gaps */
+  unsigned int borderpx;
+  unsigned int seltags;
+  unsigned int sellt;
+  unsigned int tagset[2];
+  unsigned int colorfultag;
+  int showbar, showtab;
+  int topbar, toptab;
+  Client *clients;
+  Client *sel;
+  Client *stack;
+  Monitor *next;
+  Window barwin;
+  Window tabwin;
+  Window tagwin;
+  Pixmap tagmap;
+  Imlib_Image tag_images[LENGTH(tags)];
+  int previewshow;
+  int ntabs;
+  int tab_widths[MAXTABS];
+  int tab_btn_w[3];
+  const Layout *lt[2];
+};
+
+#include "vanitygaps.c"
+#include "movestack.c"
+#include "tatami.c"
+
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags {
   char limitexceeded[LENGTH(tags) > 31 ? -1 : 1];
@@ -536,6 +539,7 @@ void arrangemon(Monitor *m) {
   updatebarpos(m);
   updatesystray();
   XMoveResizeWindow(dpy, m->tabwin, m->wx + m->gappov, m->ty, m->ww - 2 * m->gappov, th);
+  XMoveWindow(dpy, m->tagwin, m->wx + m->gappov, m->by + (m->topbar ? (bh + m->gappoh) : (- (m->mh / scalepreview) - m->gappoh)));
   strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
   if (m->lt[m->sellt]->arrange)
     m->lt[m->sellt]->arrange(m);
@@ -665,6 +669,7 @@ void cleanup(void) {
 
 void cleanupmon(Monitor *mon) {
   Monitor *m;
+  size_t i;
 
   if (mon == mons)
     mons = mons->next;
@@ -673,10 +678,19 @@ void cleanupmon(Monitor *mon) {
       ;
     m->next = mon->next;
   }
+  for (i = 0; i < LENGTH(tags); i++) {
+	  if (mon->tag_images[i]) {
+		  imlib_context_set_image(mon->tag_images[i]);
+		  imlib_free_image();
+	  }
+  }
   XUnmapWindow(dpy, mon->barwin);
   XDestroyWindow(dpy, mon->barwin);
   XUnmapWindow(dpy, mon->tabwin);
   XDestroyWindow(dpy, mon->tabwin);
+  XFreePixmap(dpy, mon->tagmap);
+  XUnmapWindow(dpy, mon->tagwin);
+  XDestroyWindow(dpy, mon->tagwin);
   free(mon);
 }
 
@@ -1950,10 +1964,13 @@ void motionnotify(XEvent *e) {
 			x += TEXTW(tags[i]);
 		while (ev->x >= x && ++i < LENGTH(tags));
 		if (i < LENGTH(tags)) {
-			if ((i + 1) != selmon->previewshow) {
+                  if ((i + 1) != selmon->previewshow && !(selmon->tagset[selmon->seltags] & 1 << i)) {
 				selmon->previewshow = i + 1;
 				showtagpreview(i);
-			}
+                  } else if (selmon->tagset[selmon->seltags] & 1 << i) {
+				selmon->previewshow = 0;
+				showtagpreview(0);
+		  }
 		} else if (selmon->previewshow != 0) {
 			selmon->previewshow = 0;
 			showtagpreview(0);
@@ -2615,10 +2632,10 @@ showtagpreview(int tag)
 		imlib_context_set_visual(DefaultVisual(dpy, screen));
 		imlib_context_set_colormap(DefaultColormap(dpy, screen));
 		imlib_context_set_drawable(selmon->tagmap);
-		imlib_render_image_part_on_drawable_at_size(0, 0, selmon->mw, selmon->mh, 0, 0, selmon->mw / 4, selmon->mh / 4);
+               	imlib_render_image_part_on_drawable_at_size(0, 0, selmon->mw, selmon->mh, 0, 0, selmon->mw / scalepreview, selmon->mh / scalepreview);
 
 		XSetWindowBackgroundPixmap(dpy, selmon->tagwin, selmon->tagmap);
-		XCopyArea(dpy, selmon->tagmap, selmon->tagwin, drw->gc, 0, 0, selmon->mw / 4, selmon->mh / 4, 0, 0);
+                XCopyArea(dpy, selmon->tagmap, selmon->tagwin, drw->gc, 0, 0, selmon->mw / scalepreview, selmon->mh / scalepreview, 0, 0);
 		XSync(dpy, False);
 		XMapWindow(dpy, selmon->tagwin);
 	} else

+ 31 - 0
chadwm/functions.h

@@ -0,0 +1,31 @@
+/* Key binding functions */
+static void defaultgaps(const Arg *arg);
+static void incrgaps(const Arg *arg);
+static void incrigaps(const Arg *arg);
+static void incrogaps(const Arg *arg);
+static void incrohgaps(const Arg *arg);
+static void incrovgaps(const Arg *arg);
+static void incrihgaps(const Arg *arg);
+static void incrivgaps(const Arg *arg);
+static void togglegaps(const Arg *arg);
+/* Layouts (delete the ones you do not need) */
+static void bstack(Monitor *m);
+static void bstackhoriz(Monitor *m);
+static void centeredmaster(Monitor *m);
+static void centeredfloatingmaster(Monitor *m);
+static void deck(Monitor *m);
+static void dwindle(Monitor *m);
+static void fibonacci(Monitor *m, int s);
+static void gaplessgrid(Monitor *m);
+static void grid(Monitor *m);
+static void horizgrid(Monitor *m);
+static void nrowgrid(Monitor *m);
+static void spiral(Monitor *m);
+static void tile(Monitor *m);
+/* Internals */
+static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
+static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
+static void setgaps(int oh, int ov, int ih, int iv);
+
+static void movestack(const Arg *arg);
+static void tatami(Monitor *m);

+ 0 - 27
chadwm/vanitygaps.c

@@ -1,30 +1,3 @@
-/* Key binding functions */
-static void defaultgaps(const Arg *arg);
-static void incrgaps(const Arg *arg);
-static void incrigaps(const Arg *arg);
-static void incrogaps(const Arg *arg);
-static void incrohgaps(const Arg *arg);
-static void incrovgaps(const Arg *arg);
-static void incrihgaps(const Arg *arg);
-static void incrivgaps(const Arg *arg);
-static void togglegaps(const Arg *arg);
-/* Layouts (delete the ones you do not need) */
-static void bstack(Monitor *m);
-static void bstackhoriz(Monitor *m);
-static void centeredmaster(Monitor *m);
-static void centeredfloatingmaster(Monitor *m);
-static void deck(Monitor *m);
-static void dwindle(Monitor *m);
-static void fibonacci(Monitor *m, int s);
-static void grid(Monitor *m);
-static void nrowgrid(Monitor *m);
-static void spiral(Monitor *m);
-static void tile(Monitor *m);
-/* Internals */
-static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
-static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
-static void setgaps(int oh, int ov, int ih, int iv);
-
 /* Settings */
 #if !PERTAG_PATCH
 static int enablegaps = 1;