Style cleanup
Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
parent
46887ac550
commit
735bed5824
|
@ -24,14 +24,16 @@ static Bool npisrelative = False;
|
||||||
|
|
||||||
#define SETPROP(p) { \
|
#define SETPROP(p) { \
|
||||||
.v = (char *[]){ "/bin/sh", "-c", \
|
.v = (char *[]){ "/bin/sh", "-c", \
|
||||||
"prop=\"`xwininfo -children -id $1 | grep '^ 0x' | sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' | xargs -0 printf %b | dmenu -l 10`\" &&" \
|
"prop=\"`xwininfo -children -id $1 | grep '^ 0x' |" \
|
||||||
|
"sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' |" \
|
||||||
|
"xargs -0 printf %b | dmenu -l 10`\" &&" \
|
||||||
"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
|
"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
|
||||||
p, winid, NULL \
|
p, winid, NULL \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MODKEY ControlMask
|
#define MODKEY ControlMask
|
||||||
static Key keys[] = { \
|
static Key keys[] = {
|
||||||
/* modifier key function argument */
|
/* modifier key function argument */
|
||||||
{ MODKEY|ShiftMask, XK_Return, focusonce, { 0 } },
|
{ MODKEY|ShiftMask, XK_Return, focusonce, { 0 } },
|
||||||
{ MODKEY|ShiftMask, XK_Return, spawn, { 0 } },
|
{ MODKEY|ShiftMask, XK_Return, spawn, { 0 } },
|
||||||
|
@ -56,9 +58,8 @@ static Key keys[] = { \
|
||||||
|
|
||||||
{ MODKEY, XK_q, killclient, { 0 } },
|
{ MODKEY, XK_q, killclient, { 0 } },
|
||||||
|
|
||||||
{ MODKEY, XK_u, focusurgent, { .v = NULL } },
|
{ MODKEY, XK_u, focusurgent, { 0 } },
|
||||||
{ MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } },
|
{ MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } },
|
||||||
|
|
||||||
{ 0, XK_F11, fullscreen, { 0 } },
|
{ 0, XK_F11, fullscreen, { 0 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,3 @@ LDFLAGS = -s ${LIBS}
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
||||||
|
|
421
tabbed.c
421
tabbed.c
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xproto.h>
|
#include <X11/Xproto.h>
|
||||||
|
@ -78,7 +78,7 @@ typedef struct {
|
||||||
} font;
|
} font;
|
||||||
} DC; /* draw context */
|
} DC; /* draw context */
|
||||||
|
|
||||||
typedef struct Client {
|
typedef struct {
|
||||||
char name[256];
|
char name[256];
|
||||||
Window win;
|
Window win;
|
||||||
int tabx;
|
int tabx;
|
||||||
|
@ -93,7 +93,6 @@ static void clientmessage(const XEvent *e);
|
||||||
static void configurenotify(const XEvent *e);
|
static void configurenotify(const XEvent *e);
|
||||||
static void configurerequest(const XEvent *e);
|
static void configurerequest(const XEvent *e);
|
||||||
static void createnotify(const XEvent *e);
|
static void createnotify(const XEvent *e);
|
||||||
static void unmapnotify(const XEvent *e);
|
|
||||||
static void destroynotify(const XEvent *e);
|
static void destroynotify(const XEvent *e);
|
||||||
static void die(const char *errstr, ...);
|
static void die(const char *errstr, ...);
|
||||||
static void drawbar(void);
|
static void drawbar(void);
|
||||||
|
@ -104,7 +103,7 @@ static void expose(const XEvent *e);
|
||||||
static void focus(int c);
|
static void focus(int c);
|
||||||
static void focusin(const XEvent *e);
|
static void focusin(const XEvent *e);
|
||||||
static void focusonce(const Arg *arg);
|
static void focusonce(const Arg *arg);
|
||||||
static void focusurgent(const Arg *);
|
static void focusurgent(const Arg *arg);
|
||||||
static void fullscreen(const Arg *arg);
|
static void fullscreen(const Arg *arg);
|
||||||
static char *getatom(int a);
|
static char *getatom(int a);
|
||||||
static int getclient(Window w);
|
static int getclient(Window w);
|
||||||
|
@ -124,13 +123,14 @@ static void resize(int c, int w, int h);
|
||||||
static void rotate(const Arg *arg);
|
static void rotate(const Arg *arg);
|
||||||
static void run(void);
|
static void run(void);
|
||||||
static void sendxembed(int c, long msg, long detail, long d1, long d2);
|
static void sendxembed(int c, long msg, long detail, long d1, long d2);
|
||||||
static void setup(void);
|
|
||||||
static void setcmd(int argc, char *argv[], int);
|
static void setcmd(int argc, char *argv[], int);
|
||||||
|
static void setup(void);
|
||||||
static void sigchld(int unused);
|
static void sigchld(int unused);
|
||||||
static void spawn(const Arg *arg);
|
static void spawn(const Arg *arg);
|
||||||
static int textnw(const char *text, unsigned int len);
|
static int textnw(const char *text, unsigned int len);
|
||||||
static void toggle(const Arg *arg);
|
static void toggle(const Arg *arg);
|
||||||
static void unmanage(int c);
|
static void unmanage(int c);
|
||||||
|
static void unmapnotify(const XEvent *e);
|
||||||
static void updatenumlockmask(void);
|
static void updatenumlockmask(void);
|
||||||
static void updatetitle(int c);
|
static void updatetitle(int c);
|
||||||
static int xerror(Display *dpy, XErrorEvent *ee);
|
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||||
|
@ -153,21 +153,21 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
|
||||||
[PropertyNotify] = propertynotify,
|
[PropertyNotify] = propertynotify,
|
||||||
};
|
};
|
||||||
static int bh, wx, wy, ww, wh;
|
static int bh, wx, wy, ww, wh;
|
||||||
static unsigned int numlockmask = 0;
|
static unsigned int numlockmask;
|
||||||
static Bool running = True, nextfocus, doinitspawn = True,
|
static Bool running = True, nextfocus, doinitspawn = True,
|
||||||
fillagain = False, closelastclient = False;
|
fillagain = False, closelastclient = False;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static DC dc;
|
static DC dc;
|
||||||
static Atom wmatom[WMLast];
|
static Atom wmatom[WMLast];
|
||||||
static Window root, win;
|
static Window root, win;
|
||||||
static Client **clients = NULL;
|
static Client **clients;
|
||||||
static int nclients = 0, sel = -1, lastsel = -1;
|
static int nclients, sel = -1, lastsel = -1;
|
||||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||||
static int cmd_append_pos = 0;
|
static int cmd_append_pos;
|
||||||
static char winid[64];
|
static char winid[64];
|
||||||
static char **cmd = NULL;
|
static char **cmd;
|
||||||
static char *wmname = "tabbed";
|
static char *wmname = "tabbed";
|
||||||
static const char *geometry = NULL;
|
static const char *geometry;
|
||||||
|
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
|
@ -175,10 +175,10 @@ char *argv0;
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
buttonpress(const XEvent *e) {
|
buttonpress(const XEvent *e)
|
||||||
|
{
|
||||||
const XButtonPressedEvent *ev = &e->xbutton;
|
const XButtonPressedEvent *ev = &e->xbutton;
|
||||||
int i;
|
int i, fc;
|
||||||
int fc;
|
|
||||||
Arg arg;
|
Arg arg;
|
||||||
|
|
||||||
if (ev->y < 0 || ev->y > bh)
|
if (ev->y < 0 || ev->y > bh)
|
||||||
|
@ -197,7 +197,7 @@ buttonpress(const XEvent *e) {
|
||||||
focus(i);
|
focus(i);
|
||||||
killclient(NULL);
|
killclient(NULL);
|
||||||
break;
|
break;
|
||||||
case Button4:
|
case Button4: /* FALLTHROUGH */
|
||||||
case Button5:
|
case Button5:
|
||||||
arg.i = ev->button == Button4 ? -1 : 1;
|
arg.i = ev->button == Button4 ? -1 : 1;
|
||||||
rotate(&arg);
|
rotate(&arg);
|
||||||
|
@ -209,7 +209,8 @@ buttonpress(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cleanup(void) {
|
cleanup(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < nclients; i++) {
|
for (i = 0; i < nclients; i++) {
|
||||||
|
@ -222,11 +223,10 @@ cleanup(void) {
|
||||||
free(clients);
|
free(clients);
|
||||||
clients = NULL;
|
clients = NULL;
|
||||||
|
|
||||||
if(dc.font.set) {
|
if (dc.font.set)
|
||||||
XFreeFontSet(dpy, dc.font.set);
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
} else {
|
else
|
||||||
XFreeFont(dpy, dc.font.xfont);
|
XFreeFont(dpy, dc.font.xfont);
|
||||||
}
|
|
||||||
|
|
||||||
XFreePixmap(dpy, dc.drawable);
|
XFreePixmap(dpy, dc.drawable);
|
||||||
XFreeGC(dpy, dc.gc);
|
XFreeGC(dpy, dc.gc);
|
||||||
|
@ -236,17 +236,18 @@ cleanup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
clientmessage(const XEvent *e) {
|
clientmessage(const XEvent *e)
|
||||||
|
{
|
||||||
const XClientMessageEvent *ev = &e->xclient;
|
const XClientMessageEvent *ev = &e->xclient;
|
||||||
|
|
||||||
if(ev->message_type == wmatom[WMProtocols]
|
if (ev->message_type == wmatom[WMProtocols] &&
|
||||||
&& ev->data.l[0] == wmatom[WMDelete]) {
|
ev->data.l[0] == wmatom[WMDelete])
|
||||||
running = False;
|
running = False;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
configurenotify(const XEvent *e) {
|
configurenotify(const XEvent *e)
|
||||||
|
{
|
||||||
const XConfigureEvent *ev = &e->xconfigure;
|
const XConfigureEvent *ev = &e->xconfigure;
|
||||||
|
|
||||||
if (ev->window == win && (ev->width != ww || ev->height != wh)) {
|
if (ev->window == win && (ev->width != ww || ev->height != wh)) {
|
||||||
|
@ -262,7 +263,8 @@ configurenotify(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
configurerequest(const XEvent *e) {
|
configurerequest(const XEvent *e)
|
||||||
|
{
|
||||||
const XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
const XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||||
XWindowChanges wc;
|
XWindowChanges wc;
|
||||||
int c;
|
int c;
|
||||||
|
@ -280,7 +282,8 @@ configurerequest(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
createnotify(const XEvent *e) {
|
createnotify(const XEvent *e)
|
||||||
|
{
|
||||||
const XCreateWindowEvent *ev = &e->xcreatewindow;
|
const XCreateWindowEvent *ev = &e->xcreatewindow;
|
||||||
|
|
||||||
if (ev->window != win && getclient(ev->window) < 0)
|
if (ev->window != win && getclient(ev->window) < 0)
|
||||||
|
@ -288,16 +291,8 @@ createnotify(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unmapnotify(const XEvent *e) {
|
destroynotify(const XEvent *e)
|
||||||
const XUnmapEvent *ev = &e->xunmap;
|
{
|
||||||
int c;
|
|
||||||
|
|
||||||
if((c = getclient(ev->window)) > -1)
|
|
||||||
unmanage(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
destroynotify(const XEvent *e) {
|
|
||||||
const XDestroyWindowEvent *ev = &e->xdestroywindow;
|
const XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
@ -306,7 +301,8 @@ destroynotify(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
die(const char *errstr, ...) {
|
die(const char *errstr, ...)
|
||||||
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, errstr);
|
va_start(ap, errstr);
|
||||||
|
@ -316,7 +312,8 @@ die(const char *errstr, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawbar(void) {
|
drawbar(void)
|
||||||
|
{
|
||||||
unsigned long *col;
|
unsigned long *col;
|
||||||
int c, cc, fc, width;
|
int c, cc, fc, width;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
@ -370,7 +367,8 @@ drawbar(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawtext(const char *text, unsigned long col[ColLast]) {
|
drawtext(const char *text, unsigned long col[ColLast])
|
||||||
|
{
|
||||||
int i, x, y, h, len, olen;
|
int i, x, y, h, len, olen;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
||||||
|
@ -388,25 +386,25 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
for (len = MIN(olen, sizeof(buf));
|
for (len = MIN(olen, sizeof(buf));
|
||||||
len && textnw(text, len) > dc.w - h; len--);
|
len && textnw(text, len) > dc.w - h; len--);
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
if(len < olen) {
|
if (len < olen)
|
||||||
for(i = len; i && i > len - 3; buf[--i] = '.');
|
for(i = len; i && i > len - 3; buf[--i] = '.');
|
||||||
}
|
|
||||||
|
|
||||||
XSetForeground(dpy, dc.gc, col[ColFG]);
|
XSetForeground(dpy, dc.gc, col[ColFG]);
|
||||||
if(dc.font.set) {
|
if (dc.font.set)
|
||||||
XmbDrawString(dpy, dc.drawable, dc.font.set,
|
XmbDrawString(dpy, dc.drawable, dc.font.set,
|
||||||
dc.gc, x, y, buf, len);
|
dc.gc, x, y, buf, len);
|
||||||
} else {
|
else
|
||||||
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ecalloc(size_t n, size_t size) {
|
ecalloc(size_t n, size_t size)
|
||||||
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!(p = calloc(n, size)))
|
if (!(p = calloc(n, size)))
|
||||||
|
@ -415,7 +413,8 @@ ecalloc(size_t n, size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
erealloc(void *o, size_t size) {
|
erealloc(void *o, size_t size)
|
||||||
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!(p = realloc(o, size)))
|
if (!(p = realloc(o, size)))
|
||||||
|
@ -424,7 +423,8 @@ erealloc(void *o, size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
expose(const XEvent *e) {
|
expose(const XEvent *e)
|
||||||
|
{
|
||||||
const XExposeEvent *ev = &e->xexpose;
|
const XExposeEvent *ev = &e->xexpose;
|
||||||
|
|
||||||
if (ev->count == 0 && win == ev->window)
|
if (ev->count == 0 && win == ev->window)
|
||||||
|
@ -432,7 +432,8 @@ expose(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
focus(int c) {
|
focus(int c)
|
||||||
|
{
|
||||||
char buf[BUFSIZ] = "tabbed-"VERSION" ::";
|
char buf[BUFSIZ] = "tabbed-"VERSION" ::";
|
||||||
size_t i, n;
|
size_t i, n;
|
||||||
XWMHints* wmh;
|
XWMHints* wmh;
|
||||||
|
@ -476,7 +477,8 @@ focus(int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
focusin(const XEvent *e) {
|
focusin(const XEvent *e)
|
||||||
|
{
|
||||||
const XFocusChangeEvent *ev = &e->xfocus;
|
const XFocusChangeEvent *ev = &e->xfocus;
|
||||||
int dummy;
|
int dummy;
|
||||||
Window focused;
|
Window focused;
|
||||||
|
@ -489,13 +491,16 @@ focusin(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
focusonce(const Arg *arg) {
|
focusonce(const Arg *arg)
|
||||||
|
{
|
||||||
nextfocus = True;
|
nextfocus = True;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
focusurgent(const Arg *args) {
|
focusurgent(const Arg *arg)
|
||||||
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
for (c = (sel + 1) % nclients; c != sel; c = (c + 1) % nclients) {
|
for (c = (sel + 1) % nclients; c != sel; c = (c + 1) % nclients) {
|
||||||
if (clients[c]->urgent) {
|
if (clients[c]->urgent) {
|
||||||
focus(c);
|
focus(c);
|
||||||
|
@ -505,7 +510,8 @@ focusurgent(const Arg *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fullscreen(const Arg *arg) {
|
fullscreen(const Arg *arg)
|
||||||
|
{
|
||||||
XEvent e;
|
XEvent e;
|
||||||
|
|
||||||
e.type = ClientMessage;
|
e.type = ClientMessage;
|
||||||
|
@ -519,7 +525,8 @@ fullscreen(const Arg *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
getatom(int a) {
|
getatom(int a)
|
||||||
|
{
|
||||||
static char buf[BUFSIZ];
|
static char buf[BUFSIZ];
|
||||||
Atom adummy;
|
Atom adummy;
|
||||||
int idummy;
|
int idummy;
|
||||||
|
@ -528,18 +535,18 @@ getatom(int a) {
|
||||||
|
|
||||||
XGetWindowProperty(dpy, win, wmatom[a], 0L, BUFSIZ, False, XA_STRING,
|
XGetWindowProperty(dpy, win, wmatom[a], 0L, BUFSIZ, False, XA_STRING,
|
||||||
&adummy, &idummy, &ldummy, &ldummy, &p);
|
&adummy, &idummy, &ldummy, &ldummy, &p);
|
||||||
if(p) {
|
if (p)
|
||||||
strncpy(buf, (char *)p, LENGTH(buf)-1);
|
strncpy(buf, (char *)p, LENGTH(buf)-1);
|
||||||
} else {
|
else
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
}
|
|
||||||
XFree(p);
|
XFree(p);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
getclient(Window w) {
|
getclient(Window w)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < nclients; i++) {
|
for (i = 0; i < nclients; i++) {
|
||||||
|
@ -551,7 +558,8 @@ getclient(Window w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
getcolor(const char *colstr) {
|
getcolor(const char *colstr)
|
||||||
|
{
|
||||||
Colormap cmap = DefaultColormap(dpy, screen);
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
XColor color;
|
XColor color;
|
||||||
|
|
||||||
|
@ -562,7 +570,8 @@ getcolor(const char *colstr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
getfirsttab(void) {
|
getfirsttab(void)
|
||||||
|
{
|
||||||
int cc, ret;
|
int cc, ret;
|
||||||
|
|
||||||
if (sel < 0)
|
if (sel < 0)
|
||||||
|
@ -573,11 +582,14 @@ getfirsttab(void) {
|
||||||
cc = (ww - TEXTW(before) - TEXTW(after)) / tabwidth;
|
cc = (ww - TEXTW(before) - TEXTW(after)) / tabwidth;
|
||||||
|
|
||||||
ret = sel - cc / 2 + (cc + 1) % 2;
|
ret = sel - cc / 2 + (cc + 1) % 2;
|
||||||
return ret < 0 ? 0 : (ret + cc > nclients ? MAX(0, nclients - cc) : ret);
|
return ret < 0 ? 0 :
|
||||||
|
ret + cc > nclients ? MAX(0, nclients - cc) :
|
||||||
|
ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
||||||
|
{
|
||||||
char **list = NULL;
|
char **list = NULL;
|
||||||
int n;
|
int n;
|
||||||
XTextProperty name;
|
XTextProperty name;
|
||||||
|
@ -592,13 +604,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
||||||
|
|
||||||
if (name.encoding == XA_STRING) {
|
if (name.encoding == XA_STRING) {
|
||||||
strncpy(text, (char *)name.value, size - 1);
|
strncpy(text, (char *)name.value, size - 1);
|
||||||
} else {
|
} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
||||||
if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
|
||||||
&& n > 0 && *list) {
|
&& n > 0 && *list) {
|
||||||
strncpy(text, *list, size - 1);
|
strncpy(text, *list, size - 1);
|
||||||
XFreeStringList(list);
|
XFreeStringList(list);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
text[size - 1] = '\0';
|
text[size - 1] = '\0';
|
||||||
XFree(name.value);
|
XFree(name.value);
|
||||||
|
|
||||||
|
@ -606,10 +616,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
initfont(const char *fontstr) {
|
initfont(const char *fontstr)
|
||||||
|
{
|
||||||
char *def, **missing, **font_names;
|
char *def, **missing, **font_names;
|
||||||
int i, n;
|
|
||||||
XFontStruct **xfonts;
|
XFontStruct **xfonts;
|
||||||
|
int i, n;
|
||||||
|
|
||||||
missing = NULL;
|
missing = NULL;
|
||||||
if (dc.font.set)
|
if (dc.font.set)
|
||||||
|
@ -625,7 +636,8 @@ initfont(const char *fontstr) {
|
||||||
if (dc.font.set) {
|
if (dc.font.set) {
|
||||||
dc.font.ascent = dc.font.descent = 0;
|
dc.font.ascent = dc.font.descent = 0;
|
||||||
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
||||||
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
for (i = 0, dc.font.ascent = 0, dc.font.descent = 0;
|
||||||
|
i < n; i++) {
|
||||||
dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
|
dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
|
||||||
dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
|
dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
|
||||||
xfonts++;
|
xfonts++;
|
||||||
|
@ -634,10 +646,9 @@ initfont(const char *fontstr) {
|
||||||
if (dc.font.xfont)
|
if (dc.font.xfont)
|
||||||
XFreeFont(dpy, dc.font.xfont);
|
XFreeFont(dpy, dc.font.xfont);
|
||||||
dc.font.xfont = NULL;
|
dc.font.xfont = NULL;
|
||||||
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
|
if (!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) &&
|
||||||
&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) {
|
!(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
|
||||||
die("tabbed: cannot load font: '%s'\n", fontstr);
|
die("tabbed: cannot load font: '%s'\n", fontstr);
|
||||||
}
|
|
||||||
|
|
||||||
dc.font.ascent = dc.font.xfont->ascent;
|
dc.font.ascent = dc.font.xfont->ascent;
|
||||||
dc.font.descent = dc.font.xfont->descent;
|
dc.font.descent = dc.font.xfont->descent;
|
||||||
|
@ -646,7 +657,8 @@ initfont(const char *fontstr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
isprotodel(int c) {
|
isprotodel(int c)
|
||||||
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
Atom *protocols;
|
Atom *protocols;
|
||||||
Bool ret = False;
|
Bool ret = False;
|
||||||
|
@ -663,23 +675,24 @@ isprotodel(int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
keypress(const XEvent *e) {
|
keypress(const XEvent *e)
|
||||||
|
{
|
||||||
const XKeyEvent *ev = &e->xkey;
|
const XKeyEvent *ev = &e->xkey;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
KeySym keysym;
|
KeySym keysym;
|
||||||
|
|
||||||
keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
|
keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
|
||||||
for (i = 0; i < LENGTH(keys); i++) {
|
for (i = 0; i < LENGTH(keys); i++) {
|
||||||
if(keysym == keys[i].keysym
|
if (keysym == keys[i].keysym &&
|
||||||
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
|
CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) &&
|
||||||
&& keys[i].func) {
|
keys[i].func)
|
||||||
keys[i].func(&(keys[i].arg));
|
keys[i].func(&(keys[i].arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
killclient(const Arg *arg) {
|
killclient(const Arg *arg)
|
||||||
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
if (sel < 0)
|
if (sel < 0)
|
||||||
|
@ -700,7 +713,8 @@ killclient(const Arg *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
manage(Window w) {
|
manage(Window w)
|
||||||
|
{
|
||||||
updatenumlockmask();
|
updatenumlockmask();
|
||||||
{
|
{
|
||||||
int i, j, nextpos;
|
int i, j, nextpos;
|
||||||
|
@ -712,17 +726,16 @@ manage(Window w) {
|
||||||
|
|
||||||
XWithdrawWindow(dpy, w, 0);
|
XWithdrawWindow(dpy, w, 0);
|
||||||
XReparentWindow(dpy, w, win, 0, bh);
|
XReparentWindow(dpy, w, win, 0, bh);
|
||||||
XSelectInput(dpy, w, PropertyChangeMask
|
XSelectInput(dpy, w, PropertyChangeMask |
|
||||||
|StructureNotifyMask|EnterWindowMask);
|
StructureNotifyMask | EnterWindowMask);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|
||||||
for (i = 0; i < LENGTH(keys); i++) {
|
for (i = 0; i < LENGTH(keys); i++) {
|
||||||
if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) {
|
if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) {
|
||||||
for (j = 0; j < LENGTH(modifiers); j++) {
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||||||
XGrabKey(dpy, code, keys[i].mod
|
XGrabKey(dpy, code, keys[i].mod |
|
||||||
| modifiers[j], w,
|
modifiers[j], w, True,
|
||||||
True, GrabModeAsync,
|
GrabModeAsync, GrabModeAsync);
|
||||||
GrabModeAsync);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,22 +749,20 @@ manage(Window w) {
|
||||||
if(npisrelative) {
|
if(npisrelative) {
|
||||||
nextpos = sel + newposition;
|
nextpos = sel + newposition;
|
||||||
} else {
|
} else {
|
||||||
if(newposition < 0) {
|
if (newposition < 0)
|
||||||
nextpos = nclients - newposition;
|
nextpos = nclients - newposition;
|
||||||
} else {
|
else
|
||||||
nextpos = newposition;
|
nextpos = newposition;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (nextpos >= nclients)
|
if (nextpos >= nclients)
|
||||||
nextpos = nclients - 1;
|
nextpos = nclients - 1;
|
||||||
if (nextpos < 0)
|
if (nextpos < 0)
|
||||||
nextpos = 0;
|
nextpos = 0;
|
||||||
|
|
||||||
if(nclients > 1 && nextpos < nclients - 1) {
|
if (nclients > 1 && nextpos < nclients - 1)
|
||||||
memmove(&clients[nextpos + 1], &clients[nextpos],
|
memmove(&clients[nextpos + 1], &clients[nextpos],
|
||||||
sizeof(Client *) *
|
sizeof(Client *) * (nclients - nextpos - 1));
|
||||||
(nclients - nextpos - 1));
|
|
||||||
}
|
|
||||||
clients[nextpos] = c;
|
clients[nextpos] = c;
|
||||||
updatetitle(nextpos);
|
updatetitle(nextpos);
|
||||||
|
|
||||||
|
@ -774,13 +785,16 @@ manage(Window w) {
|
||||||
/* Adjust sel before focus does set it to lastsel. */
|
/* Adjust sel before focus does set it to lastsel. */
|
||||||
if (sel >= nextpos)
|
if (sel >= nextpos)
|
||||||
sel++;
|
sel++;
|
||||||
focus((nextfocus)? nextpos : ((sel < 0)? 0 : sel));
|
focus(nextfocus ? nextpos :
|
||||||
|
sel < 0 ? 0 :
|
||||||
|
sel);
|
||||||
nextfocus = foreground;
|
nextfocus = foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
maprequest(const XEvent *e) {
|
maprequest(const XEvent *e)
|
||||||
|
{
|
||||||
const XMapRequestEvent *ev = &e->xmaprequest;
|
const XMapRequestEvent *ev = &e->xmaprequest;
|
||||||
|
|
||||||
if (getclient(ev->window) < 0)
|
if (getclient(ev->window) < 0)
|
||||||
|
@ -788,13 +802,15 @@ maprequest(const XEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
move(const Arg *arg) {
|
move(const Arg *arg)
|
||||||
|
{
|
||||||
if (arg->i >= 0 && arg->i < nclients)
|
if (arg->i >= 0 && arg->i < nclients)
|
||||||
focus(arg->i);
|
focus(arg->i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
movetab(const Arg *arg) {
|
movetab(const Arg *arg)
|
||||||
|
{
|
||||||
int c;
|
int c;
|
||||||
Client *new;
|
Client *new;
|
||||||
|
|
||||||
|
@ -802,14 +818,16 @@ movetab(const Arg *arg) {
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
c += nclients;
|
c += nclients;
|
||||||
|
|
||||||
if(sel < 0 || (c == sel))
|
if (sel < 0 || c == sel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new = clients[sel];
|
new = clients[sel];
|
||||||
if (sel < c)
|
if (sel < c)
|
||||||
memmove(&clients[sel], &clients[sel+1], sizeof(Client *) * (c - sel));
|
memmove(&clients[sel], &clients[sel+1],
|
||||||
|
sizeof(Client *) * (c - sel));
|
||||||
else
|
else
|
||||||
memmove(&clients[c+1], &clients[c], sizeof(Client *) * (sel - c));
|
memmove(&clients[c+1], &clients[c],
|
||||||
|
sizeof(Client *) * (sel - c));
|
||||||
clients[c] = new;
|
clients[c] = new;
|
||||||
sel = c;
|
sel = c;
|
||||||
|
|
||||||
|
@ -817,7 +835,8 @@ movetab(const Arg *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
propertynotify(const XEvent *e) {
|
propertynotify(const XEvent *e)
|
||||||
|
{
|
||||||
const XPropertyEvent *ev = &e->xproperty;
|
const XPropertyEvent *ev = &e->xproperty;
|
||||||
XWMHints *wmh;
|
XWMHints *wmh;
|
||||||
int c;
|
int c;
|
||||||
|
@ -834,38 +853,44 @@ propertynotify(const XEvent *e) {
|
||||||
arg.v = cmd;
|
arg.v = cmd;
|
||||||
spawn(&arg);
|
spawn(&arg);
|
||||||
}
|
}
|
||||||
} else if(ev->state == PropertyNewValue && ev->atom == XA_WM_HINTS
|
} else if (ev->state == PropertyNewValue && ev->atom == XA_WM_HINTS &&
|
||||||
&& (c = getclient(ev->window)) > -1
|
(c = getclient(ev->window)) > -1 &&
|
||||||
&& (wmh = XGetWMHints(dpy, clients[c]->win))) {
|
(wmh = XGetWMHints(dpy, clients[c]->win))) {
|
||||||
if (wmh->flags & XUrgencyHint) {
|
if (wmh->flags & XUrgencyHint) {
|
||||||
XFree(wmh);
|
XFree(wmh);
|
||||||
wmh = XGetWMHints(dpy, win);
|
wmh = XGetWMHints(dpy, win);
|
||||||
if (c != sel) {
|
if (c != sel) {
|
||||||
if(urgentswitch && wmh && !(wmh->flags & XUrgencyHint)) {
|
if (urgentswitch && wmh &&
|
||||||
/* only switch, if tabbed was focused since last urgency hint
|
!(wmh->flags & XUrgencyHint)) {
|
||||||
* if WMHints could not be received, default to no switch */
|
/* only switch, if tabbed was focused
|
||||||
|
* since last urgency hint if WMHints
|
||||||
|
* could not be received,
|
||||||
|
* default to no switch */
|
||||||
focus(c);
|
focus(c);
|
||||||
} else {
|
} else {
|
||||||
/* if no switch should be performed, mark tab as urgent */
|
/* if no switch should be performed,
|
||||||
|
* mark tab as urgent */
|
||||||
clients[c]->urgent = True;
|
clients[c]->urgent = True;
|
||||||
drawbar();
|
drawbar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (wmh && !(wmh->flags & XUrgencyHint)) {
|
if (wmh && !(wmh->flags & XUrgencyHint)) {
|
||||||
/* update tabbed urgency hint if not set already */
|
/* update tabbed urgency hint
|
||||||
|
* if not set already */
|
||||||
wmh->flags |= XUrgencyHint;
|
wmh->flags |= XUrgencyHint;
|
||||||
XSetWMHints(dpy, win, wmh);
|
XSetWMHints(dpy, win, wmh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFree(wmh);
|
XFree(wmh);
|
||||||
} else if(ev->state != PropertyDelete && ev->atom == XA_WM_NAME
|
} else if (ev->state != PropertyDelete && ev->atom == XA_WM_NAME &&
|
||||||
&& (c = getclient(ev->window)) > -1) {
|
(c = getclient(ev->window)) > -1) {
|
||||||
updatetitle(c);
|
updatetitle(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
resize(int c, int w, int h) {
|
resize(int c, int w, int h)
|
||||||
|
{
|
||||||
XConfigureEvent ce;
|
XConfigureEvent ce;
|
||||||
XWindowChanges wc;
|
XWindowChanges wc;
|
||||||
|
|
||||||
|
@ -887,7 +912,8 @@ resize(int c, int w, int h) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rotate(const Arg *arg) {
|
rotate(const Arg *arg)
|
||||||
|
{
|
||||||
int nsel = -1;
|
int nsel = -1;
|
||||||
|
|
||||||
if (sel < 0)
|
if (sel < 0)
|
||||||
|
@ -908,7 +934,8 @@ rotate(const Arg *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run(void) {
|
run(void)
|
||||||
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
/* main event loop */
|
/* main event loop */
|
||||||
|
@ -925,7 +952,8 @@ run(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sendxembed(int c, long msg, long detail, long d1, long d2) {
|
sendxembed(int c, long msg, long detail, long d1, long d2)
|
||||||
|
{
|
||||||
XEvent e = { 0 };
|
XEvent e = { 0 };
|
||||||
|
|
||||||
e.xclient.window = clients[c]->win;
|
e.xclient.window = clients[c]->win;
|
||||||
|
@ -941,21 +969,23 @@ sendxembed(int c, long msg, long detail, long d1, long d2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setcmd(int argc, char *argv[], int replace) {
|
setcmd(int argc, char *argv[], int replace)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cmd = ecalloc(argc + 3, sizeof *cmd);
|
cmd = ecalloc(argc + 3, sizeof(*cmd));
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
return;
|
return;
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
cmd[i] = argv[i];
|
cmd[i] = argv[i];
|
||||||
cmd[(replace > 0)? replace : argc] = winid;
|
cmd[replace > 0 ? replace : argc] = winid;
|
||||||
cmd_append_pos = argc + !replace;
|
cmd_append_pos = argc + !replace;
|
||||||
cmd[cmd_append_pos] = cmd[cmd_append_pos + 1] = NULL;
|
cmd[cmd_append_pos] = cmd[cmd_append_pos + 1] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setup(void) {
|
setup(void)
|
||||||
|
{
|
||||||
int bitm, tx, ty, tw, th, dh, dw, isfixed;
|
int bitm, tx, ty, tw, th, dh, dw, isfixed;
|
||||||
XWMHints *wmh;
|
XWMHints *wmh;
|
||||||
XClassHint class_hint;
|
XClassHint class_hint;
|
||||||
|
@ -971,13 +1001,14 @@ setup(void) {
|
||||||
bh = dc.h = dc.font.height + 2;
|
bh = dc.h = dc.font.height + 2;
|
||||||
|
|
||||||
/* init atoms */
|
/* init atoms */
|
||||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
|
||||||
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||||
wmatom[XEmbed] = XInternAtom(dpy, "_XEMBED", False);
|
wmatom[WMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN",
|
||||||
|
False);
|
||||||
wmatom[WMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
wmatom[WMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||||
wmatom[WMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||||
wmatom[WMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
|
||||||
wmatom[WMSelectTab] = XInternAtom(dpy, "_TABBED_SELECT_TAB", False);
|
wmatom[WMSelectTab] = XInternAtom(dpy, "_TABBED_SELECT_TAB", False);
|
||||||
|
wmatom[WMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||||
|
wmatom[XEmbed] = XInternAtom(dpy, "_XEMBED", False);
|
||||||
|
|
||||||
/* init appearance */
|
/* init appearance */
|
||||||
wx = 0;
|
wx = 0;
|
||||||
|
@ -1029,8 +1060,9 @@ setup(void) {
|
||||||
dc.norm[ColFG], dc.norm[ColBG]);
|
dc.norm[ColFG], dc.norm[ColBG]);
|
||||||
XMapRaised(dpy, win);
|
XMapRaised(dpy, win);
|
||||||
XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
|
XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
|
||||||
ButtonPressMask|ExposureMask|KeyPressMask|PropertyChangeMask|
|
ButtonPressMask | ExposureMask | KeyPressMask |
|
||||||
StructureNotifyMask|SubstructureRedirectMask);
|
PropertyChangeMask | StructureNotifyMask |
|
||||||
|
SubstructureRedirectMask);
|
||||||
xerrorxlib = XSetErrorHandler(xerror);
|
xerrorxlib = XSetErrorHandler(xerror);
|
||||||
|
|
||||||
class_hint.res_name = wmname;
|
class_hint.res_name = wmname;
|
||||||
|
@ -1062,7 +1094,8 @@ setup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sigchld(int unused) {
|
sigchld(int unused)
|
||||||
|
{
|
||||||
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
||||||
die("tabbed: cannot install SIGCHLD handler");
|
die("tabbed: cannot install SIGCHLD handler");
|
||||||
|
|
||||||
|
@ -1070,7 +1103,8 @@ sigchld(int unused) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spawn(const Arg *arg) {
|
spawn(const Arg *arg)
|
||||||
|
{
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
if(dpy)
|
if(dpy)
|
||||||
close(ConnectionNumber(dpy));
|
close(ConnectionNumber(dpy));
|
||||||
|
@ -1091,12 +1125,12 @@ spawn(const Arg *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
textnw(const char *text, unsigned int len) {
|
textnw(const char *text, unsigned int len)
|
||||||
|
{
|
||||||
XRectangle r;
|
XRectangle r;
|
||||||
|
|
||||||
if (dc.font.set) {
|
if (dc.font.set) {
|
||||||
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
||||||
|
|
||||||
return r.width;
|
return r.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,12 +1138,14 @@ textnw(const char *text, unsigned int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
toggle(const Arg *arg) {
|
toggle(const Arg *arg)
|
||||||
|
{
|
||||||
*(Bool*) arg->v = !*(Bool*) arg->v;
|
*(Bool*) arg->v = !*(Bool*) arg->v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
unmanage(int c) {
|
unmanage(int c)
|
||||||
|
{
|
||||||
if (c < 0 || c >= nclients) {
|
if (c < 0 || c >= nclients) {
|
||||||
drawbar();
|
drawbar();
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
@ -1140,17 +1176,15 @@ unmanage(int c) {
|
||||||
if (nclients <= 0) {
|
if (nclients <= 0) {
|
||||||
lastsel = sel = -1;
|
lastsel = sel = -1;
|
||||||
|
|
||||||
if(closelastclient) {
|
if (closelastclient)
|
||||||
running = False;
|
running = False;
|
||||||
} else if(fillagain && running) {
|
else if (fillagain && running)
|
||||||
spawn(NULL);
|
spawn(NULL);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if(lastsel >= nclients) {
|
if (lastsel >= nclients)
|
||||||
lastsel = nclients - 1;
|
lastsel = nclients - 1;
|
||||||
} else if(lastsel > c) {
|
else if (lastsel > c)
|
||||||
lastsel--;
|
lastsel--;
|
||||||
}
|
|
||||||
|
|
||||||
if (c == sel && lastsel >= 0) {
|
if (c == sel && lastsel >= 0) {
|
||||||
focus(lastsel);
|
focus(lastsel);
|
||||||
|
@ -1169,7 +1203,18 @@ unmanage(int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
updatenumlockmask(void) {
|
unmapnotify(const XEvent *e)
|
||||||
|
{
|
||||||
|
const XUnmapEvent *ev = &e->xunmap;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
if ((c = getclient(ev->window)) > -1)
|
||||||
|
unmanage(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
updatenumlockmask(void)
|
||||||
|
{
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
XModifierKeymap *modmap;
|
XModifierKeymap *modmap;
|
||||||
|
|
||||||
|
@ -1178,22 +1223,20 @@ updatenumlockmask(void) {
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
for (j = 0; j < modmap->max_keypermod; j++) {
|
for (j = 0; j < modmap->max_keypermod; j++) {
|
||||||
if (modmap->modifiermap[i * modmap->max_keypermod + j]
|
if (modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||||
== XKeysymToKeycode(dpy,
|
== XKeysymToKeycode(dpy, XK_Num_Lock))
|
||||||
XK_Num_Lock)) {
|
|
||||||
numlockmask = (1 << i);
|
numlockmask = (1 << i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
XFreeModifiermap(modmap);
|
XFreeModifiermap(modmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
updatetitle(int c) {
|
updatetitle(int c)
|
||||||
if(!gettextprop(clients[c]->win, wmatom[WMName],
|
{
|
||||||
clients[c]->name, sizeof(clients[c]->name))) {
|
if (!gettextprop(clients[c]->win, wmatom[WMName], clients[c]->name,
|
||||||
gettextprop(clients[c]->win, XA_WM_NAME,
|
sizeof(clients[c]->name)))
|
||||||
clients[c]->name, sizeof(clients[c]->name));
|
gettextprop(clients[c]->win, XA_WM_NAME, clients[c]->name,
|
||||||
}
|
sizeof(clients[c]->name));
|
||||||
if (sel == c)
|
if (sel == c)
|
||||||
xsettitle(win, clients[c]->name);
|
xsettitle(win, clients[c]->name);
|
||||||
drawbar();
|
drawbar();
|
||||||
|
@ -1203,26 +1246,26 @@ updatetitle(int c) {
|
||||||
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
|
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
|
||||||
* default error handler, which may call exit. */
|
* default error handler, which may call exit. */
|
||||||
int
|
int
|
||||||
xerror(Display *dpy, XErrorEvent *ee) {
|
xerror(Display *dpy, XErrorEvent *ee)
|
||||||
|
{
|
||||||
if (ee->error_code == BadWindow
|
if (ee->error_code == BadWindow
|
||||||
|| (ee->request_code == X_SetInputFocus
|
|| (ee->request_code == X_SetInputFocus &&
|
||||||
&& ee->error_code == BadMatch)
|
ee->error_code == BadMatch)
|
||||||
|| (ee->request_code == X_PolyText8
|
|| (ee->request_code == X_PolyText8 &&
|
||||||
&& ee->error_code == BadDrawable)
|
ee->error_code == BadDrawable)
|
||||||
|| (ee->request_code == X_PolyFillRectangle
|
|| (ee->request_code == X_PolyFillRectangle &&
|
||||||
&& ee->error_code == BadDrawable)
|
ee->error_code == BadDrawable)
|
||||||
|| (ee->request_code == X_PolySegment
|
|| (ee->request_code == X_PolySegment &&
|
||||||
&& ee->error_code == BadDrawable)
|
ee->error_code == BadDrawable)
|
||||||
|| (ee->request_code == X_ConfigureWindow
|
|| (ee->request_code == X_ConfigureWindow &&
|
||||||
&& ee->error_code == BadMatch)
|
ee->error_code == BadMatch)
|
||||||
|| (ee->request_code == X_GrabButton
|
|| (ee->request_code == X_GrabButton &&
|
||||||
&& ee->error_code == BadAccess)
|
ee->error_code == BadAccess)
|
||||||
|| (ee->request_code == X_GrabKey
|
|| (ee->request_code == X_GrabKey &&
|
||||||
&& ee->error_code == BadAccess)
|
ee->error_code == BadAccess)
|
||||||
|| (ee->request_code == X_CopyArea
|
|| (ee->request_code == X_CopyArea &&
|
||||||
&& ee->error_code == BadDrawable)) {
|
ee->error_code == BadDrawable))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "tabbed: fatal error: request code=%d, error code=%d\n",
|
fprintf(stderr, "tabbed: fatal error: request code=%d, error code=%d\n",
|
||||||
ee->request_code, ee->error_code);
|
ee->request_code, ee->error_code);
|
||||||
|
@ -1230,28 +1273,29 @@ xerror(Display *dpy, XErrorEvent *ee) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xsettitle(Window w, const char *str) {
|
xsettitle(Window w, const char *str)
|
||||||
|
{
|
||||||
XTextProperty xtp;
|
XTextProperty xtp;
|
||||||
|
|
||||||
if(XmbTextListToTextProperty(dpy, (char **)&str, 1, XCompoundTextStyle,
|
if (XmbTextListToTextProperty(dpy, (char **)&str, 1,
|
||||||
&xtp) == Success) {
|
XCompoundTextStyle, &xtp) == Success) {
|
||||||
XSetTextProperty(dpy, w, &xtp, wmatom[WMName]);
|
XSetTextProperty(dpy, w, &xtp, wmatom[WMName]);
|
||||||
XSetTextProperty(dpy, w, &xtp, XA_WM_NAME);
|
XSetTextProperty(dpy, w, &xtp, XA_WM_NAME);
|
||||||
XFree(xtp.value);
|
XFree(xtp.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *argv0;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void) {
|
usage(void)
|
||||||
die("usage: %s [-dfhsv] [-g geometry] [-n name] [-p [s+/-]pos] [-r narg] "
|
{
|
||||||
"[-o color] [-O color] [-t color] [-T color] [-u color] [-U color] "
|
die("usage: %s [-dfhsv] [-g geometry] [-n name] [-p [s+/-]pos] "
|
||||||
"command...\n", argv0);
|
"[-r narg] [-o color] [-O color] [-t color] [-T color] "
|
||||||
|
"[-u color] [-U color] command...\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
Bool detach = False;
|
Bool detach = False;
|
||||||
int replace = 0;
|
int replace = 0;
|
||||||
char *pstr;
|
char *pstr;
|
||||||
|
@ -1273,6 +1317,12 @@ main(int argc, char *argv[]) {
|
||||||
case 'n':
|
case 'n':
|
||||||
wmname = EARGF(usage());
|
wmname = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
|
case 'O':
|
||||||
|
normfgcolor = EARGF(usage());
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
normbgcolor = EARGF(usage());
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pstr = EARGF(usage());
|
pstr = EARGF(usage());
|
||||||
if (pstr[0] == 's') {
|
if (pstr[0] == 's') {
|
||||||
|
@ -1288,30 +1338,24 @@ main(int argc, char *argv[]) {
|
||||||
case 's':
|
case 's':
|
||||||
doinitspawn = False;
|
doinitspawn = False;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'T':
|
||||||
normbgcolor = EARGF(usage());
|
selfgcolor = EARGF(usage());
|
||||||
break;
|
|
||||||
case 'O':
|
|
||||||
normfgcolor = EARGF(usage());
|
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
selbgcolor = EARGF(usage());
|
selbgcolor = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'U':
|
||||||
selfgcolor = EARGF(usage());
|
urgfgcolor = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
urgbgcolor = EARGF(usage());
|
urgbgcolor = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'U':
|
|
||||||
urgfgcolor = EARGF(usage());
|
|
||||||
break;
|
|
||||||
case 'v':
|
case 'v':
|
||||||
die("tabbed-"VERSION", © 2009-2016"
|
die("tabbed-"VERSION", © 2009-2016"
|
||||||
" tabbed engineers, see LICENSE"
|
" tabbed engineers, see LICENSE"
|
||||||
" for details.\n");
|
" for details.\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default: /* FALLTHROUGH */
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
@ -1324,9 +1368,9 @@ main(int argc, char *argv[]) {
|
||||||
setcmd(argc, argv, replace);
|
setcmd(argc, argv, replace);
|
||||||
|
|
||||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
fprintf(stderr, "tabbed: no locale support\n");
|
fprintf(stderr, "%s: no locale support\n", argv0);
|
||||||
if (!(dpy = XOpenDisplay(NULL)))
|
if (!(dpy = XOpenDisplay(NULL)))
|
||||||
die("tabbed: cannot open display\n");
|
die("%s: cannot open display\n", argv0);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
printf("0x%lx\n", win);
|
printf("0x%lx\n", win);
|
||||||
|
@ -1348,4 +1392,3 @@ main(int argc, char *argv[]) {
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
xembed.c
3
xembed.c
|
@ -8,7 +8,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *xembed;
|
char *xembed;
|
||||||
int tty;
|
int tty;
|
||||||
|
@ -43,4 +43,3 @@ noembed:
|
||||||
perror(argv[0]); /* failed to execute */
|
perror(argv[0]); /* failed to execute */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue