main.c
author Anselm R. Garbe <arg@10kloc.org>
Tue, 12 Sep 2006 10:57:28 +0200
changeset 461 9d23330a5268
parent 458 81fcd7ddafee
child 473 2d8af0d7920d
permissions -rw-r--r--
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     1
/*
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     2
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     3
 * See LICENSE file for license details.
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     4
 */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     5
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     6
#include "dwm.h"
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
     7
#include <errno.h>
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     8
#include <stdio.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     9
#include <stdlib.h>
57
f005d46462e8 implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents: 52
diff changeset
    10
#include <string.h>
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
    11
#include <unistd.h>
138
c1185dc7a36e some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents: 137
diff changeset
    12
#include <sys/select.h>
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    13
#include <X11/cursorfont.h>
291
8e6e0aa5e2ae removed NUMLOCKMASK, added dynamically calculated numlockmask instead
Anselm R.Garbe <arg@10ksloc.org>
parents: 281
diff changeset
    14
#include <X11/keysym.h>
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    15
#include <X11/Xatom.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    16
#include <X11/Xproto.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    17
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    18
/* extern */
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    19
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    20
char stext[1024];
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    21
Bool *seltag;
362
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 359
diff changeset
    22
int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh;
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 359
diff changeset
    23
unsigned int ntags, numlockmask;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    24
Atom wmatom[WMLast], netatom[NetLast];
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    25
Bool running = True;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    26
Bool issel = True;
400
052657ff2e7b applied Sanders max_and_focus.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
    27
Bool maximized = False;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    28
Client *clients = NULL;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    29
Client *sel = NULL;
446
a2e587651c79 using a global stack for focus recovery on arrange() - seems to work great
Anselm R. Garbe <arg@10kloc.org>
parents: 433
diff changeset
    30
Client *stack = NULL;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    31
Cursor cursor[CurLast];
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    32
Display *dpy;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    33
DC dc = {0};
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    34
Window root, barwin;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    35
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
    36
/* static */
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    37
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
    38
static int (*xerrorxlib)(Display *, XErrorEvent *);
302
3b11e32e8d7e we close stdin as well
Anselm R.Garbe <arg@10ksloc.org>
parents: 295
diff changeset
    39
static Bool otherwm, readin;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    40
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    41
static void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
    42
cleanup() {
302
3b11e32e8d7e we close stdin as well
Anselm R.Garbe <arg@10ksloc.org>
parents: 295
diff changeset
    43
	close(STDIN_FILENO);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    44
	while(sel) {
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
    45
		resize(sel, True, TopLeft);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    46
		unmanage(sel);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    47
	}
295
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    48
	if(dc.font.set)
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    49
		XFreeFontSet(dpy, dc.font.set);
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    50
	else
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    51
		XFreeFont(dpy, dc.font.xfont);
292
4aa632b6ba66 changed main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 291
diff changeset
    52
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
295
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    53
	XFreePixmap(dpy, dc.drawable);
7565875d07d3 extended cleanup
Anselm R.Garbe <arg@10ksloc.org>
parents: 293
diff changeset
    54
	XFreeGC(dpy, dc.gc);
309
204427dcc087 corrected order of cleanup code
Anselm R.Garbe <arg@10ksloc.org>
parents: 302
diff changeset
    55
	XDestroyWindow(dpy, barwin);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    56
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
292
4aa632b6ba66 changed main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 291
diff changeset
    57
	XSync(dpy, False);
433
a6b8994af164 small fix
Anselm R. Garbe <arg@10kloc.org>
parents: 400
diff changeset
    58
	free(seltag);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    59
}
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    60
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    61
static void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
    62
scan() {
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    63
	unsigned int i, num;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
    64
	Window *wins, d1, d2;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    65
	XWindowAttributes wa;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    66
292
4aa632b6ba66 changed main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 291
diff changeset
    67
	wins = NULL;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    68
	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    69
		for(i = 0; i < num; i++) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    70
			if(!XGetWindowAttributes(dpy, wins[i], &wa))
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    71
				continue;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    72
			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    73
				continue;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    74
			if(wa.map_state == IsViewable)
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
    75
				manage(wins[i], &wa);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    76
		}
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    77
	}
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    78
	if(wins)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    79
		XFree(wins);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    80
}
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    81
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    82
static void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
    83
setup() {
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    84
	int i, j;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    85
	unsigned int mask;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    86
	Window w;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    87
	XModifierKeymap *modmap;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    88
	XSetWindowAttributes wa;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    89
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    90
	/* init atoms */
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    91
	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    92
	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    93
	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    94
	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    95
	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    96
			PropModeReplace, (unsigned char *) netatom, NetLast);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    97
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    98
	/* init cursors */
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
    99
	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   100
	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   101
	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   102
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   103
	modmap = XGetModifierMapping(dpy);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   104
	for (i = 0; i < 8; i++) {
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   105
		for (j = 0; j < modmap->max_keypermod; j++) {
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   106
			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   107
				numlockmask = (1 << i);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   108
		}
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   109
	}
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   110
	XFree(modmap);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   111
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   112
	wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   113
		| EnterWindowMask | LeaveWindowMask;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   114
	wa.cursor = cursor[CurNormal];
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   115
	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   116
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   117
	grabkeys();
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   118
	initrregs();
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   119
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   120
	for(ntags = 0; tags[ntags]; ntags++);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   121
	seltag = emallocz(sizeof(Bool) * ntags);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   122
	seltag[0] = True;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   123
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   124
	/* style */
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   125
	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   126
	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   127
	dc.sel[ColBG] = getcolor(SELBGCOLOR);
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   128
	dc.sel[ColFG] = getcolor(SELFGCOLOR);
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   129
	dc.status[ColBG] = getcolor(STATUSBGCOLOR);
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   130
	dc.status[ColFG] = getcolor(STATUSFGCOLOR);
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   131
	setfont(FONT);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   132
362
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 359
diff changeset
   133
	bmw = textw(FLOATSYMBOL) > textw(TILESYMBOL) ? textw(FLOATSYMBOL) : textw(TILESYMBOL);
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   134
	sx = sy = 0;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   135
	sw = DisplayWidth(dpy, screen);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   136
	sh = DisplayHeight(dpy, screen);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   137
	mw = (sw * MASTERW) / 100;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   138
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   139
	bx = by = 0;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   140
	bw = sw;
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   141
	dc.h = bh = dc.font.height + 2;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   142
	wa.override_redirect = 1;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   143
	wa.background_pixmap = ParentRelative;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   144
	wa.event_mask = ButtonPressMask | ExposureMask;
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   145
	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   146
			CopyFromParent, DefaultVisual(dpy, screen),
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   147
			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   148
	XDefineCursor(dpy, barwin, cursor[CurNormal]);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   149
	XMapRaised(dpy, barwin);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   150
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   151
	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   152
	dc.gc = XCreateGC(dpy, root, 0, 0);
344
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 339
diff changeset
   153
	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   154
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   155
	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   156
	strcpy(stext, "dwm-"VERSION);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   157
}
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   158
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   159
/*
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   160
 * Startup Error handler to check if another window manager
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   161
 * is already running.
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   162
 */
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   163
static int
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   164
xerrorstart(Display *dsply, XErrorEvent *ee) {
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   165
	otherwm = True;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   166
	return -1;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   167
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   168
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   169
/* extern */
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   170
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   171
int
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   172
getproto(Window w) {
329
cea0c98495bc rearranged getproto
Anselm R. Garbe <arg@10kloc.org>
parents: 328
diff changeset
   173
	int i, format, protos, status;
328
083f1f3e1e93 removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents: 326
diff changeset
   174
	unsigned long extra, res;
083f1f3e1e93 removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents: 326
diff changeset
   175
	Atom *protocols, real;
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   176
329
cea0c98495bc rearranged getproto
Anselm R. Garbe <arg@10kloc.org>
parents: 328
diff changeset
   177
	protos = 0;
cea0c98495bc rearranged getproto
Anselm R. Garbe <arg@10kloc.org>
parents: 328
diff changeset
   178
	status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L, False,
cea0c98495bc rearranged getproto
Anselm R. Garbe <arg@10kloc.org>
parents: 328
diff changeset
   179
			XA_ATOM, &real, &format, &res, &extra, (unsigned char **)&protocols);
328
083f1f3e1e93 removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents: 326
diff changeset
   180
	if(status != Success || protocols == 0)
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   181
		return protos;
329
cea0c98495bc rearranged getproto
Anselm R. Garbe <arg@10kloc.org>
parents: 328
diff changeset
   182
	for(i = 0; i < res; i++)
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   183
		if(protocols[i] == wmatom[WMDelete])
157
93012e947eae renamed WM_PROTOCOL_DELWIN into PROTODELWIN
arg@10ksloc.org
parents: 146
diff changeset
   184
			protos |= PROTODELWIN;
328
083f1f3e1e93 removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents: 326
diff changeset
   185
	free(protocols);
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   186
	return protos;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   187
}
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   188
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   189
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   190
sendevent(Window w, Atom a, long value) {
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   191
	XEvent e;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   192
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   193
	e.type = ClientMessage;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   194
	e.xclient.window = w;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   195
	e.xclient.message_type = a;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   196
	e.xclient.format = 32;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   197
	e.xclient.data.l[0] = value;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   198
	e.xclient.data.l[1] = CurrentTime;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   199
	XSendEvent(dpy, w, False, NoEventMask, &e);
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 78
diff changeset
   200
	XSync(dpy, False);
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   201
}
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   202
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   203
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   204
quit(Arg *arg) {
302
3b11e32e8d7e we close stdin as well
Anselm R.Garbe <arg@10ksloc.org>
parents: 295
diff changeset
   205
	readin = running = False;
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   206
}
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   207
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   208
/*
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   209
 * There's no way to check accesses to destroyed windows, thus those cases are
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   210
 * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs
455
4e3e22673073 fixed some other comments, now also the code side seems to be at a level to be reviewed by experienced programmers
Anselm R. Garbe <arg@10kloc.org>
parents: 446
diff changeset
   211
 * default error handler, which may call exit.
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   212
 */
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
   213
int
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   214
xerror(Display *dpy, XErrorEvent *ee) {
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   215
	if(ee->error_code == BadWindow
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   216
	|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   217
	|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   218
	|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   219
	|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   220
	|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
458
81fcd7ddafee applied Christof Musik's multihead patch for a pathologic cornercase
Anselm R. Garbe <arg@10kloc.org>
parents: 455
diff changeset
   221
	|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
81fcd7ddafee applied Christof Musik's multihead patch for a pathologic cornercase
Anselm R. Garbe <arg@10kloc.org>
parents: 455
diff changeset
   222
	|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   223
		return 0;
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
   224
	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 99
diff changeset
   225
		ee->request_code, ee->error_code);
455
4e3e22673073 fixed some other comments, now also the code side seems to be at a level to be reviewed by experienced programmers
Anselm R. Garbe <arg@10kloc.org>
parents: 446
diff changeset
   226
	return xerrorxlib(dpy, ee); /* may call exit */
27
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
   227
}
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
   228
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   229
int
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 458
diff changeset
   230
main(int argc, char *argv[]) {
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   231
	int r, xfd;
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
   232
	fd_set rd;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   233
137
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 126
diff changeset
   234
	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 126
diff changeset
   235
		fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 126
diff changeset
   236
		exit(EXIT_SUCCESS);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   237
	}
137
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 126
diff changeset
   238
	else if(argc != 1)
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 126
diff changeset
   239
		eprint("usage: dwm [-v]\n");
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   240
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   241
	dpy = XOpenDisplay(0);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   242
	if(!dpy)
197
c13f374f836c slight fix
arg@10ksloc.org
parents: 191
diff changeset
   243
		eprint("dwm: cannot open display\n");
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   244
265
573b1c4a71a4 reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
   245
	xfd = ConnectionNumber(dpy);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   246
	screen = DefaultScreen(dpy);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   247
	root = RootWindow(dpy, screen);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   248
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   249
	otherwm = False;
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   250
	XSetErrorHandler(xerrorstart);
197
c13f374f836c slight fix
arg@10ksloc.org
parents: 191
diff changeset
   251
	/* this causes an error if some other window manager is running */
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   252
	XSelectInput(dpy, root, SubstructureRedirectMask);
78
0d71fb80b592 changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents: 77
diff changeset
   253
	XSync(dpy, False);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   254
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   255
	if(otherwm)
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   256
		eprint("dwm: another window manager is already running\n");
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   257
292
4aa632b6ba66 changed main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 291
diff changeset
   258
	XSync(dpy, False);
78
0d71fb80b592 changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents: 77
diff changeset
   259
	XSetErrorHandler(NULL);
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   260
	xerrorxlib = XSetErrorHandler(xerror);
275
425cd4490c1e some other small fixes
Anselm R.Garbe <arg@10ksloc.org>
parents: 274
diff changeset
   261
	XSync(dpy, False);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   262
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   263
	setup();
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   264
	drawstatus();
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   265
	scan();
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
   266
214
51ac019cf587 small fix of a comment
arg@10ksloc.org
parents: 203
diff changeset
   267
	/* main event loop, also reads status text from stdin */
242
cd15de32e173 prepared 0.8
Anselm R.Garbe <arg@10ksloc.org>
parents: 237
diff changeset
   268
	XSync(dpy, False);
292
4aa632b6ba66 changed main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 291
diff changeset
   269
	procevent();
302
3b11e32e8d7e we close stdin as well
Anselm R.Garbe <arg@10ksloc.org>
parents: 295
diff changeset
   270
	readin = True;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
   271
	while(running) {
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
   272
		FD_ZERO(&rd);
164
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   273
		if(readin)
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   274
			FD_SET(STDIN_FILENO, &rd);
265
573b1c4a71a4 reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
   275
		FD_SET(xfd, &rd);
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   276
		r = select(xfd + 1, &rd, NULL, NULL, NULL);
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   277
		if((r == -1) && (errno == EINTR))
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
   278
			continue;
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   279
		if(r > 0) {
164
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   280
			if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   281
				readin = NULL != fgets(stext, sizeof(stext), stdin);
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   282
				if(readin)
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   283
					stext[strlen(stext) - 1] = 0;
162
a6a31e485fbd dwm is now exit, if stdin is closed due broken pipe
arg@10ksloc.org
parents: 157
diff changeset
   284
				else 
164
21071ae1fe68 made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents: 162
diff changeset
   285
					strcpy(stext, "broken pipe");
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   286
				drawstatus();
59
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
   287
			}
5d4653de9a1c implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents: 58
diff changeset
   288
		}
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 329
diff changeset
   289
		else if(r < 0)
316
d69cdb180a3e small changes to dwm.1, rearranged order within main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents: 309
diff changeset
   290
			eprint("select failed\n");
293
093744cc5353 applied jk_to_tab patch
Anselm R.Garbe <arg@10ksloc.org>
parents: 292
diff changeset
   291
		procevent();
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
   292
	}
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   293
	cleanup();
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   294
	XCloseDisplay(dpy);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   295
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   296
	return 0;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   297
}