-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabbed.diff
186 lines (173 loc) · 5.16 KB
/
tabbed.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
diff --git a/Makefile b/Makefile
index dda3cdb..b6c04ec 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ DOCPREFIX = ${PREFIX}/share/doc/${NAME}
# use system flags.
TABBED_CFLAGS = -I/usr/X11R6/include -I/usr/include/freetype2 ${CFLAGS}
-TABBED_LDFLAGS = -L/usr/X11R6/lib -lX11 -lfontconfig -lXft ${LDFLAGS}
+TABBED_LDFLAGS = -L/usr/X11R6/lib -lX11 -lfontconfig -lXft -lXrender ${LDFLAGS}
TABBED_CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700L
# OpenBSD (uncomment)
diff --git a/tabbed.c b/tabbed.c
index 81be5e4..07dc6a6 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -89,6 +89,7 @@ typedef struct {
/* function declarations */
static void buttonpress(const XEvent *e);
+static void motionnotify(const XEvent *e);
static void cleanup(void);
static void clientmessage(const XEvent *e);
static void configurenotify(const XEvent *e);
@@ -151,6 +152,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
[KeyPress] = keypress,
[MapRequest] = maprequest,
[PropertyNotify] = propertynotify,
+ [MotionNotify] = motionnotify,
};
static int bh, obh, wx, wy, ww, wh;
static unsigned int numlockmask;
@@ -170,6 +172,9 @@ static char **cmd;
static char *wmname = "tabbed";
static const char *geometry;
+static Colormap cmap;
+static Visual *visual = NULL;
+
char *argv0;
/* configuration, allows nested code to access above variables */
@@ -209,6 +214,41 @@ buttonpress(const XEvent *e)
}
}
+void
+motionnotify(const XEvent *e)
+{
+ const XMotionEvent *ev = &e->xmotion;
+ int i, fc;
+ Arg arg;
+
+ if (ev->y < 0 || ev->y > bh)
+ return;
+
+ if (! (ev->state & Button1Mask)) {
+ return;
+ }
+
+ if (((fc = getfirsttab()) > 0 && ev->x < TEXTW(before)) || ev->x < 0)
+ return;
+
+ if (sel < 0)
+ return;
+
+ for (i = fc; i < nclients; i++) {
+ if (clients[i]->tabx > ev->x) {
+ if (i == sel+1) {
+ arg.i = 1;
+ movetab(&arg);
+ }
+ if (i == sel-1) {
+ arg.i = -1;
+ movetab(&arg);
+ }
+ break;
+ }
+ }
+}
+
void
cleanup(void)
{
@@ -254,8 +294,8 @@ configurenotify(const XEvent *e)
ww = ev->width;
wh = ev->height;
XFreePixmap(dpy, dc.drawable);
- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
- DefaultDepth(dpy, screen));
+ dc.drawable = XCreatePixmap(dpy, win, ww, wh,
+ 32);
if (!obh && (wh <= bh)) {
obh = bh;
@@ -407,7 +447,7 @@ drawtext(const char *text, XftColor col[ColLast])
;
}
- d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
+ d = XftDrawCreate(dpy, dc.drawable, visual, cmap);
XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
XftDrawDestroy(d);
}
@@ -575,7 +615,7 @@ getcolor(const char *colstr)
{
XftColor color;
- if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
+ if (!XftColorAllocName(dpy, visual, cmap, colstr, &color))
die("%s: cannot allocate color '%s'\n", argv0, colstr);
return color;
@@ -1037,23 +1077,65 @@ setup(void)
wy = dh + wy - wh - 1;
}
+ XVisualInfo *vis;
+ XRenderPictFormat *fmt;
+ int nvi;
+ int i;
+
+ XVisualInfo tpl = {
+ .screen = screen,
+ .depth = 32,
+ .class = TrueColor
+ };
+
+ vis = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi);
+ for(i = 0; i < nvi; i ++) {
+ fmt = XRenderFindVisualFormat(dpy, vis[i].visual);
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+ visual = vis[i].visual;
+ break;
+ }
+ }
+
+ XFree(vis);
+
+ if (! visual) {
+ fprintf(stderr, "Couldn't find ARGB visual.\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visual, None);
dc.norm[ColBG] = getcolor(normbgcolor);
dc.norm[ColFG] = getcolor(normfgcolor);
dc.sel[ColBG] = getcolor(selbgcolor);
dc.sel[ColFG] = getcolor(selfgcolor);
dc.urg[ColBG] = getcolor(urgbgcolor);
dc.urg[ColFG] = getcolor(urgfgcolor);
- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
- DefaultDepth(dpy, screen));
- dc.gc = XCreateGC(dpy, root, 0, 0);
- win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0,
- dc.norm[ColFG].pixel, dc.norm[ColBG].pixel);
+ XSetWindowAttributes attrs;
+ attrs.background_pixel = dc.norm[ColBG].pixel;
+ attrs.border_pixel = dc.norm[ColFG].pixel;
+ attrs.bit_gravity = NorthWestGravity;
+ attrs.event_mask = FocusChangeMask | KeyPressMask
+ | ExposureMask | VisibilityChangeMask | StructureNotifyMask
+ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+ attrs.background_pixmap = None ;
+ attrs.colormap = cmap;
+
+ win = XCreateWindow(dpy, root, wx, wy,
+ ww, wh, 0, 32, InputOutput,
+ visual, CWBackPixmap | CWBorderPixel | CWBitGravity
+ | CWEventMask | CWColormap, &attrs);
+
+ dc.drawable = XCreatePixmap(dpy, win, ww, wh,
+ 32);
+ dc.gc = XCreateGC(dpy, dc.drawable, 0, 0);
+
XMapRaised(dpy, win);
XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
ButtonPressMask | ExposureMask | KeyPressMask |
PropertyChangeMask | StructureNotifyMask |
- SubstructureRedirectMask);
+ SubstructureRedirectMask | ButtonMotionMask);
xerrorxlib = XSetErrorHandler(xerror);
class_hint.res_name = wmname;