draw.c
author arg@mmvi
Fri, 15 Sep 2006 14:21:25 +0200
changeset 466 ad3fa2d18542
parent 461 9d23330a5268
child 486 8d564b9e3cd4
permissions -rw-r--r--
added visibility check to enternotify as well
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     1
/*
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     2
 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     3
 * See LICENSE file for license details.
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     4
 */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     5
#include "dwm.h"
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     6
#include <stdio.h>
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     7
#include <string.h>
32
082c75b937b5 removed unnecessary crap
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
     8
#include <X11/Xlocale.h>
082c75b937b5 removed unnecessary crap
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
     9
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
    10
/* static */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    11
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    12
static unsigned 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: 377
diff changeset
    13
textnw(const char *text, unsigned int len) {
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    14
	XRectangle r;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 93
diff changeset
    15
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    16
	if(dc.font.set) {
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    17
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    18
		return r.width;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    19
	}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    20
	return XTextWidth(dc.font.xfont, text, len);
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    21
}
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    22
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    23
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: 377
diff changeset
    24
drawtext(const char *text, unsigned long col[ColLast], Bool highlight) {
344
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    25
	int x, y, w, h;
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    26
	static char buf[256];
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    27
	unsigned int len, olen;
352
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    28
	XGCValues gcv;
344
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    29
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    30
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    31
	XSetForeground(dpy, dc.gc, col[ColBG]);
344
93192711a36a changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents: 342
diff changeset
    32
	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
237
7f8f7f14e9cd readded border color, this sucks least
Anselm R.Garbe <arg@10ksloc.org>
parents: 236
diff changeset
    33
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
    34
	if(!text)
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    35
		return;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    36
218
c674a0baac63 changed signature of drawtext
arg@10ksloc.org
parents: 208
diff changeset
    37
	w = 0;
269
bf6792e3e700 fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
    38
	olen = len = strlen(text);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    39
	if(len >= sizeof(buf))
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    40
		len = sizeof(buf) - 1;
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
    41
	memcpy(buf, text, len);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    42
	buf[len] = 0;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    43
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
    44
	h = dc.font.ascent + dc.font.descent;
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
    45
	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
    46
	x = dc.x + (h / 2);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    47
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    48
	/* shorten text if necessary */
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
    49
	while(len && (w = textnw(buf, len)) > dc.w - h)
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    50
		buf[--len] = 0;
269
bf6792e3e700 fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
    51
	if(len < olen) {
273
ffc73b32084a fixed string cutting
Anselm R.Garbe <arg@10ksloc.org>
parents: 269
diff changeset
    52
		if(len > 1)
ffc73b32084a fixed string cutting
Anselm R.Garbe <arg@10ksloc.org>
parents: 269
diff changeset
    53
			buf[len - 1] = '.';
ffc73b32084a fixed string cutting
Anselm R.Garbe <arg@10ksloc.org>
parents: 269
diff changeset
    54
		if(len > 2)
ffc73b32084a fixed string cutting
Anselm R.Garbe <arg@10ksloc.org>
parents: 269
diff changeset
    55
			buf[len - 2] = '.';
269
bf6792e3e700 fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
    56
		if(len > 3)
273
ffc73b32084a fixed string cutting
Anselm R.Garbe <arg@10ksloc.org>
parents: 269
diff changeset
    57
			buf[len - 3] = '.';
269
bf6792e3e700 fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents: 262
diff changeset
    58
	}
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    59
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
    60
	if(w > dc.w)
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    61
		return; /* too long */
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    62
	gcv.foreground = col[ColFG];
352
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    63
	if(dc.font.set) {
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    64
		XChangeGC(dpy, dc.gc, GCForeground, &gcv);
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
    65
		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
352
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    66
	}
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    67
	else {
352
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    68
		gcv.font = dc.font.xfont->fid;
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    69
		XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
    70
		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
    71
	}
345
977585eb2d35 found less intrusive way
Anselm R. Garbe <arg@10kloc.org>
parents: 344
diff changeset
    72
	if(highlight) {
352
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    73
		r.x = dc.x + 2;
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    74
		r.y = dc.y + 2;
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    75
		r.width = r.height = 3;
5a8bdc3b37cb back to 3 colors
Anselm R. Garbe <arg@10kloc.org>
parents: 351
diff changeset
    76
		XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    77
	}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    78
}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    79
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
    80
/* extern */
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    81
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    82
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: 377
diff changeset
    83
drawall() {
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    84
	Client *c;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    85
142
9b9deafa0508 committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents: 124
diff changeset
    86
	for(c = clients; c; c = getnext(c->next))
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    87
		drawtitle(c);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    88
	drawstatus();
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    89
}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    90
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    91
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: 377
diff changeset
    92
drawstatus() {
124
75576e44c1d8 made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents: 123
diff changeset
    93
	int i, x;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    94
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    95
	dc.x = dc.y = 0;
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    96
178
e848966a1ac6 removed TLast tag enum, now tags is simple defined as char *[] array, the rest is calculated correctly, rules take an int array for the tags
arg@10ksloc.org
parents: 173
diff changeset
    97
	for(i = 0; i < ntags; i++) {
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    98
		dc.w = textw(tags[i]);
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
    99
		if(seltag[i])
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   100
			drawtext(tags[i], dc.sel, sel && sel->tags[i]);
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   101
		else
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   102
			drawtext(tags[i], dc.norm, sel && sel->tags[i]);
362
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 361
diff changeset
   103
		dc.x += dc.w;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   104
	}
362
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 361
diff changeset
   105
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 361
diff changeset
   106
	dc.w = bmw;
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 361
diff changeset
   107
	drawtext(arrange == dotile ? TILESYMBOL : FLOATSYMBOL, dc.status, False);
ba6c55e1b9b2 trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents: 361
diff changeset
   108
361
728e74820e1d removed small 1px gap, somehow without it things feel better
Anselm R. Garbe <arg@10kloc.org>
parents: 360
diff changeset
   109
	x = dc.x + dc.w;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   110
	dc.w = textw(stext);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   111
	dc.x = bx + bw - dc.w;
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   112
	if(dc.x < x) {
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   113
		dc.x = x;
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   114
		dc.w = bw - x;
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   115
	}
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   116
	drawtext(stext, dc.status, False);
340
ae0affabdc02 implemented right tag drawing in the status bar and titlebars
Anselm R. Garbe <arg@10kloc.org>
parents: 334
diff changeset
   117
371
fc9d35252ab4 applied sanders somepatches.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
   118
	if((dc.w = dc.x - x) > bh) {
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   119
		dc.x = x;
371
fc9d35252ab4 applied sanders somepatches.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
   120
		if(sel)
fc9d35252ab4 applied sanders somepatches.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
   121
			drawtext(sel->name, dc.sel, False);
fc9d35252ab4 applied sanders somepatches.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
   122
		else
fc9d35252ab4 applied sanders somepatches.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 362
diff changeset
   123
			drawtext(NULL, dc.norm, False);
124
75576e44c1d8 made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents: 123
diff changeset
   124
	}
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   125
	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 77
diff changeset
   126
	XSync(dpy, False);
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   127
}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   128
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   129
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: 377
diff changeset
   130
drawtitle(Client *c) {
239
e5390f8e06b9 applied sumik's multihead patch
Anselm R.Garbe <arg@10ksloc.org>
parents: 237
diff changeset
   131
	if(c == sel && issel) {
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   132
		drawstatus();
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   133
		XUnmapWindow(dpy, c->twin);
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   134
		XSetWindowBorder(dpy, c->win, dc.sel[ColBG]);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   135
		return;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   136
	}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   137
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   138
	XSetWindowBorder(dpy, c->win, dc.norm[ColBG]);
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   139
	XMapWindow(dpy, c->twin);
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   140
	dc.x = dc.y = 0;
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   141
	dc.w = c->tw;
353
8a06efe5b563 new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents: 352
diff changeset
   142
	drawtext(c->name, dc.norm, False);
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   143
	XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0);
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 77
diff changeset
   144
	XSync(dpy, False);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   145
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   146
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   147
unsigned long
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: 377
diff changeset
   148
getcolor(const char *colstr) {
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 93
diff changeset
   149
	Colormap cmap = DefaultColormap(dpy, screen);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   150
	XColor color;
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   151
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   152
	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   153
	return color.pixel;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   154
}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   155
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   156
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: 377
diff changeset
   157
setfont(const char *fontstr) {
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   158
	char **missing, *def;
33
e90449e03167 new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents: 32
diff changeset
   159
	int i, n;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   160
7
49e2fc9fb94f new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 5
diff changeset
   161
	missing = NULL;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   162
	setlocale(LC_ALL, "");
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   163
	if(dc.font.set)
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   164
		XFreeFontSet(dpy, dc.font.set);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   165
	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   166
	if(missing) {
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   167
		while(n--)
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   168
			fprintf(stderr, "missing fontset: %s\n", missing[n]);
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   169
		XFreeStringList(missing);
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   170
		if(dc.font.set) {
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   171
			XFreeFontSet(dpy, dc.font.set);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   172
			dc.font.set = NULL;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   173
		}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   174
	}
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   175
	if(dc.font.set) {
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   176
		XFontSetExtents *font_extents;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   177
		XFontStruct **xfonts;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   178
		char **font_names;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   179
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   180
		dc.font.ascent = dc.font.descent = 0;
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   181
		font_extents = XExtentsOfFontSet(dc.font.set);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   182
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   183
		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   184
			if(dc.font.ascent < (*xfonts)->ascent)
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   185
				dc.font.ascent = (*xfonts)->ascent;
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   186
			if(dc.font.descent < (*xfonts)->descent)
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   187
				dc.font.descent = (*xfonts)->descent;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   188
			xfonts++;
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   189
		}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   190
	}
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   191
	else {
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   192
		if(dc.font.xfont)
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   193
			XFreeFont(dpy, dc.font.xfont);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   194
		dc.font.xfont = NULL;
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   195
		dc.font.xfont = XLoadQueryFont(dpy, fontstr);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   196
		if (!dc.font.xfont)
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   197
			dc.font.xfont = XLoadQueryFont(dpy, "fixed");
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   198
		if (!dc.font.xfont)
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   199
			eprint("error, cannot init 'fixed' font\n");
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   200
		dc.font.ascent = dc.font.xfont->ascent;
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   201
		dc.font.descent = dc.font.xfont->descent;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   202
	}
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
   203
	dc.font.height = dc.font.ascent + dc.font.descent;
2
a79188fe4a40 added new stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   204
}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   205
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   206
unsigned 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: 377
diff changeset
   207
textw(const char *text) {
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   208
	return textnw(text, strlen(text)) + dc.font.height;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   209
}