• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Japanese translation of message catalog for Sawfish Window-Manager


Commit MetaInfo

修訂11a52b93c0b8d965907270518ea11cf3f0207c61 (tree)
時間2010-12-19 13:32:12
作者Michal Maruska <mmaruska@gmai...>
CommiterMichal Maruska

Log Message

merge of mmc-focus,mmc-debug into mmc-focus-verbose

Conflicts:
src/events.c
src/windows.c

Change Summary

差異

--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -28,7 +28,7 @@ VPATH=@srcdir@:@top_srcdir@
2828
2929 SRCS := colors.c cursors.c display.c events.c fonts.c frames.c \
3030 functions.c images.c keys.c main.c multihead.c pixmap-cache.c \
31- property-cache.c server.c session.c stacking-list.c windows.c
31+ property-cache.c server.c session.c stacking-list.c windows.c mmc.c
3232 OBJS := $(SRCS:.c=.o)
3333
3434 DL_SRCS := gradient.c flippers.c x.c selection.c
--- /dev/null
+++ b/src/debug-colors.h
@@ -0,0 +1,81 @@
1+#ifndef DEBUG_COLORS_H
2+#define DEBUG_COLORS_H
3+
4+
5+#define color_green "\x1b[43;30m" /* i have */
6+
7+/*was printf*/
8+#define color_reset "\x1b[0m"
9+/* requests: */
10+#define unmap_request_color "\x1b[48;5;209;38;5;232m"
11+#define map_request_color "\x1b[48;5;203;38;5;232m"
12+
13+#define flow_color "\x1b[31m"
14+#define event_color "\x1b[01;36m"
15+#define serial_color "\x1b[01;33m"
16+#define events_color "\x1b[01;32;45m" /* how many events */
17+/* #define event_color "\x1b[46;30m" */
18+#define event_name_color "\x1b[01;45;37m"
19+
20+#define frame_color "\x1b[48;5;177;38;5;232m"
21+/* #define frame_color "\x1b[38;5;119m" */
22+
23+#define move_color "\x1b[38;5;119m"
24+
25+#define reparent_color "\x1b[38;5;119m"
26+
27+/* for stacking! */
28+#define functions_color "\x1b[30;43m"
29+#define message_color "\x1b[33;1m"
30+
31+
32+#define property_color "\x1b[33;1m"
33+#define time_color "\x1b[33m"
34+#define stacking_color "\x1b[38;5;204m"
35+
36+#define window_color "\x1b[38;5;123m"
37+#define frame_window_color "\x1b[38;5;10m"
38+#define image_color "\x1b[48;5;177;38;5;159m"
39+
40+
41+/* fixme: I could simply output 2 Esc. sequences! */
42+static
43+inline char*
44+color_fg_string(char* string, int part, char* buffer)
45+{
46+#define BUFFER_SIZE 20
47+#if 0
48+ static char buffer[BUFFER_SIZE];
49+#endif
50+
51+#if 0
52+ /* number_2_string ? */
53+ strncat(buffer, BUFFER_SIZE, string, (toa part), );
54+#else
55+ snprintf(buffer, BUFFER_SIZE, "%s%dm", string, part);
56+#endif
57+ return buffer;
58+}
59+
60+#define focus_mode_color "\x1b[01;37m"
61+
62+/* no! */
63+#define focus_color "\x1b[38;5;204m"
64+#define another_focus_color "\x1b[31m"
65+#define warning_color "\x1b[48;5;46;38;5;22m"
66+#define error_color "\x1b[01;37;41m"
67+
68+#define xkb_color "\x1b[01;42;30m"
69+#define keys_color "\x1b[01;36m"
70+
71+#define configure_color "\x1b[48;5;153m"
72+
73+/* events: */
74+#define unmap_color "\x1b[38;5;209m"
75+#define map_color "\x1b[38;5;203m"
76+/*#define map_color "\x1b[01;46;31m" */
77+#define grab_color "\x1b[38;5;46m"
78+#define xgrab_color "\x1b[01;33;41m"
79+
80+
81+#endif /* DEBUG_COLORS_H */
--- /dev/null
+++ b/src/debug.h
@@ -0,0 +1,156 @@
1+#ifndef DEBUG_H
2+#define DEBUG_H
3+
4+#include "sawfish.h"
5+
6+/* format specifier */
7+#define FMT_XID "lx" /* XID */
8+#define FMT_WIN FMT_XID /* Window is unsigned long */
9+
10+
11+#define DEBUG 1
12+
13+#define XAllowEvents_string "\x1b[01;33;41mXAllowEvents\x1b[0m"
14+
15+
16+#define DB_EVENTS_FLOW 1 /* 1 */
17+
18+#define DB_EVENTS_MAP (1<<1) /* 2 */
19+#define DB_EVENTS_UNMAP (1<<2) /* 4 */
20+#define DB_EVENTS_FOCUS (1<<3) /* 8 */ // 188 = 128 + 60 = 32 + 16 + 8 + 4 56 = 32 + 16 + 8
21+
22+/* 4+8 = 14 +16 = 30 */
23+
24+#define DB_EVENTS_TIME (1<<4) /* 16 */
25+
26+#define DB_EVENTS_COLOR (1<<5) /* 32 */
27+#define DB_EVENTS_PROPERTY (1<<6) /* 64 */
28+#define DB_EVENTS_MISC (1<<7)/* 128 216 = 128 + 64 + 16 8 -64 152 */
29+#define DB_EVENTS_QUEUE (1<<8) /* 256 */
30+
31+#define DB_EVENTS_QUEUE (1<<8) /* 256 */
32+
33+#define DB_EVENTS_CONFIGURE (1 << 9) /* 1 */
34+/* */
35+
36+#define DB_FUNCTIONS_GRAB (1<<1)
37+#define DB_FUNCTIONS_REST (1<<7)
38+#define DB_FUNCTIONS_MOUSE (1<<2)
39+#define DB_FUNCTIONS_MOVE (1<<3) /* 8*/
40+
41+#define DB_FUNCTIONS_MESSAGE (1<<4) /* 16 */
42+
43+#define DB_FUNCTIONS_PROP (1<<5) /* 32 */
44+
45+
46+
47+#define DB_WINDOWS_FOCUS 1
48+
49+#define DB_WINDOWS_PROT (1 << 1) /* protocol */
50+#define DB_WINDOWS_ADD (1 << 2) /* 4 */
51+#define DB_WINDOWS_FRAME (1 << 3) /* 8 */
52+
53+
54+#define DB_WINDOWS_PUT (1 << 4) /* ??? */
55+
56+#define DB_WINDOWS_HOOKS (1<<6) /* 64 */
57+#define DB_WINDOWS_REST (1<<7) /* 128 */
58+
59+#define DB_WINDOWS_FIND (1<<8)
60+#define DB_WINDOWS_GC (1<<9)
61+
62+#define DB_DISPLAY_ERROR 1
63+
64+
65+#define DB_KEYS_INTER 4
66+#define DB_KEYS_FLOW 128
67+#define DB_KEYS_GRAB 2
68+#define DB_KEYS_WINDOW 8
69+#define DB_KEYS_WINDOW_DETAIL 16
70+
71+
72+#define DB_FRAMES_FRAME (1 << 0) /* 2 */
73+
74+// ???
75+#define DB_FRAMES_PARTS (1 << 1) /* 2 */
76+
77+
78+#define DB_FRAMES_SHAPE (1 << 2) /* 4 */
79+// #define DB_FRAMES_SHAPE (1 << 9) /* 512 */
80+
81+#define DB_FRAMES_PARTS_CONFIGURE (1 << 3) /* configure FPs to change their size/position */
82+
83+#define DB_FRAMES_BUILD (1 << 4) /* 16 */
84+
85+
86+#define DB_FRAMES_ALLOC (1 << 5) /* 32 */
87+#define DB_FRAMES_RE (1 << 6) /* 64 ... */
88+
89+#define DB_FRAMES_PARTS_BUILD (1 << 7) /* 128 */
90+
91+// fixme: should use `DB_FRAMES_RE'
92+#define DB_FRAMES_PARTS_CHANGE (1 << 8) /* 256 */
93+
94+
95+#define DB_FRAMES_DRAW (1 <<9) /* 512 */
96+
97+
98+
99+
100+#define DB_IMAGES_CREATE (1 << 1)
101+#define DB_IMAGES_RENDER (1 << 2) /* 4 */
102+#define DB_IMAGES_OPS (1 << 3)
103+#define DB_IMAGES_GET (1 << 4)
104+#define DB_IMAGES_GC (1 << 5)
105+
106+
107+
108+#define DB_CACHE_DELETE (1 << 1)
109+#define DB_CACHE_REF (1 << 2)
110+#define DB_CACHE_MISS (1 << 3) /* 8 */
111+
112+
113+#define DB_STACKING_PROT (1 << 1) /* protocol */
114+#define DB_STACKING_ALGO (1 << 2) /* 4 */
115+#define DB_STACKING_WINDOWS_FRAME (1 << 3)
116+
117+
118+
119+/* frame options:
120+ * 1 Frame bg black & pixmamp None!
121+ * 2 atomic
122+ * 4 pixbuf cache works as I want:
123+ * 8 DBE
124+ * 16 ??
125+ * 32 DO refresh_frame_parts before Expose iff 1
126+ *
127+ * 43 = 32 + 11 = 8 + 3 = 2+1
128+ * 64 .... allow XConfigure on the FPs (which need it)
129+
130+ * 128 do not refresh on expose a traced FP
131+
132+ * 256 make all gravity static
133+ * 512 ... don't reconfigure FPs .. rely on gravity!
134+ * 1024 ... predict the reposition & maybe change the gravity?
135+ * 2048 ... clearArea on each configure
136+ */
137+
138+
139+extern int debug_keys;
140+extern int debug_stacking;
141+extern int debug_events;
142+extern int debug_functions;
143+extern int debug_windows;
144+extern int debug_frames;
145+extern int debug_frame_part;
146+extern int debug_images;
147+extern int debug_cache;
148+extern int debug_display;
149+
150+
151+/* options */
152+extern int default_grab_owner;
153+extern int dont_allow_events;
154+
155+
156+#endif /* DEBUG_H */
--- a/src/display.c
+++ b/src/display.c
@@ -31,6 +31,7 @@
3131 #include <stdarg.h>
3232 #include <ctype.h>
3333
34+#include <X11/Xproto.h>
3435 #ifdef HAVE_UNIX
3536 # ifdef HAVE_FCNTL_H
3637 # include <fcntl.h>
@@ -50,6 +51,14 @@ int screen_num, screen_width, screen_height;
5051 Window root_window, no_focus_window;
5152 int shape_event_base, shape_error_base;
5253
54+int debug_display;
55+/* A table of strings, probably in Xlib already? */
56+#include "errors.h"
57+#include "debug.h"
58+#include "debug-colors.h"
59+int debug_display = DB_DISPLAY_ERROR; /* a good default! */
60+
61+
5362 Visual *preferred_visual;
5463 int preferred_depth;
5564
@@ -63,6 +72,39 @@ DEFSYM(canonical_display_name, "canonical-display-name");
6372
6473 /* X error handlers */
6574
75+static const char*
76+request_name (int request)
77+{
78+ request--;
79+ /* return a string with the name, or NULL */
80+ if ((request >= 0) &&
81+ (request < (sizeof(request_names)/sizeof(request_names[0]))))
82+ return request_names[request];
83+ else
84+ return NULL;
85+}
86+
87+static void
88+print_error (XErrorEvent *ev)
89+{
90+ char buf[256];
91+ const char* name = request_name(ev->request_code);
92+
93+ XGetErrorText(dpy, ev->error_code, buf, sizeof(buf));
94+ fprintf(stderr, "X Error: %s\n", buf);
95+
96+ if (name)
97+ fprintf(stderr, "The request was: %s, serial %lu\n", name, ev->serial);
98+ else
99+ fprintf(stderr, "The request was from some extension)!\n");
100+
101+ fprintf(stderr, " Request Major code: %d\n", ev->request_code);
102+ fprintf(stderr, " Request Minor code: %d\n", ev->minor_code);
103+ fprintf(stderr, " ResourceId 0x%x (%d)\n", (unsigned int)ev->resourceid,
104+ (unsigned int)ev->resourceid);
105+ /* i prefer to see both decimal and hexadecimal */
106+}
107+
66108 /* General error handler. Probably due to lag between windows being
67109 killed and us receiving DestroyNotify events */
68110 static int
@@ -70,6 +112,12 @@ error_handler (Display *dpy, XErrorEvent *ev)
70112 {
71113 Lisp_Window *w;
72114
115+ DB(("%s%s%s serial %u, XID %" FMT_XID ", type %d, %s\n", error_color, __FUNCTION__,
116+ color_reset,
117+ ev->serial, ev->resourceid, ev->type, request_name(ev->request_code)));
118+ if (debug_display & DB_DISPLAY_ERROR)
119+ print_error (ev);
120+
73121 if (ev->resourceid != 0
74122 && (ev->error_code == BadWindow || ev->error_code == BadDrawable))
75123 {
--- a/src/events.c
+++ b/src/events.c
@@ -32,6 +32,10 @@
3232 #include <glib.h>
3333 #include <stdio.h>
3434
35+#include "debug.h"
36+#include "debug-colors.h"
37+int debug_events;
38+
3539 /* Lookup table of event handlers */
3640 void (*event_handlers[LASTEvent])(XEvent *ev);
3741
@@ -125,6 +129,8 @@ DEFSYM(normal, "normal");
125129 DEFSYM(grab, "grab");
126130 DEFSYM(ungrab, "ungrab");
127131
132+extern repv Qeval_key_release_events;
133+
128134 repv Fsynthetic_configure_mutex (repv);
129135
130136 /* `Time' will always be 32-bits, due to underlying wire protocol (?) */
@@ -309,6 +315,12 @@ colormap_notify (XEvent *ev)
309315 static void
310316 key_press (XEvent *ev)
311317 {
318+ Lisp_Window *w = find_window_by_id (ev->xkey.window);
319+ if (debug_keys & DB_KEYS_FLOW)
320+ DB (("E: %s [%s %u @ %lu]-> eval_input_event (%s)\n", __FUNCTION__,
321+ ev->type == KeyPress? "keyPress": "keyRelease",
322+ ev->xkey.keycode, ev->xkey.time,
323+ window_name (w)));
312324 record_mouse_position (ev->xkey.x_root, ev->xkey.y_root, ev->type, 0);
313325
314326 /* Don't look for a context map, frame parts are never focused */
@@ -1515,6 +1527,133 @@ inner_handle_input (repv arg)
15151527 return Qnil;
15161528 }
15171529
1530+
1531+static void
1532+report_event (XEvent *xev)
1533+{
1534+#ifdef USE_XKB
1535+ /* indeed!! */
1536+ if (debug_events)
1537+ report_xkb_event(xev);
1538+#endif
1539+ /* debugging + skipping Release */
1540+ switch (xev->type)
1541+ {
1542+ case KeyRelease:
1543+ case KeyPress:
1544+ {
1545+ char buf[256]; /* static ? */
1546+ u_long code, mods;
1547+
1548+ /* mmc: I prefer to see (the key combination pressed/release) here,
1549+ * se I run the lookup here: */
1550+ if (!translate_event (&code, &mods, &xev))
1551+ break; /* why ??? */
1552+
1553+ lookup_event_name(buf, code, mods);
1554+
1555+
1556+ char* name = "unknown window";
1557+ /* do i need to protect it from GC? */
1558+ Lisp_Window* kw = find_window_by_id(xev->xkey.window);
1559+ if (kw)
1560+ name = (char *) rep_STR (kw->name);
1561+ else if (xev->xkey.window == no_focus_window)
1562+ name = "no_focus_window";
1563+ else if (xev->xkey.window == root_window)
1564+ name = (xev->xkey.subwindow == no_focus_window ) ?
1565+ "no_focus_window via root_window" : "root_window";
1566+
1567+ // xev->xkey.subwindow
1568+ if (debug_keys) /* & DB_EVENTS_TIME */
1569+ DB (("** Key: serial:%s%d%s %s %s time: %u %s%s%s/%d %d\n",
1570+ keys_color ,xev->xkey.serial, color_reset,
1571+ xev->type < LASTEvent ?event_names[xev->type]:"unknown event",
1572+ buf,
1573+ xev->xkey.time, /*my_timestamp(xev->xkey.time),*/
1574+ name,
1575+
1576+ (kw && (kw->id == xev->xkey.window)) ? "window (grab?)" :
1577+ ((kw && (kw->frame == xev->xkey.window)) ? "frame" : ""),
1578+
1579+ (xev->xkey.subwindow == xev->xkey.window) ? "" : "->subwindow"
1580+ ,xev->xkey.window, xev->xkey.subwindow
1581+ /*xev->xkey.time*/
1582+ ));
1583+ if (xev->type==KeyRelease
1584+ && (global_symbol_value (Qeval_key_release_events) == Qnil));
1585+ /* why ?? ... so assert? */
1586+ break;
1587+ }
1588+ default:
1589+ if (! ((xev->type == Expose)
1590+ // || (xev->type == PropertyNotify)
1591+ || (xev->type == VisibilityNotify)
1592+
1593+ /* if i set DB_EVENTS_MISC -> i want to see even those */
1594+ || (!(debug_events & DB_EVENTS_MISC)
1595+ &&
1596+ (((xev->type == UnmapNotify)
1597+ || (xev->type == ConfigureNotify)
1598+ || (xev->type == MapNotify))
1599+ && (xev->xany.window == root_window)))
1600+ /* 64 root_window ... this means, that the event is reported to the root.*/
1601+ ))
1602+ {
1603+ /* do */
1604+ if (debug_events & DB_EVENTS_FLOW)
1605+ {
1606+ /* i'm not interested that the event arrived via root_window !! */
1607+ Window id = xev->xany.window;
1608+ Window event = xev->xany.window;
1609+
1610+ switch (xev->type){
1611+ case UnmapNotify:
1612+ id = xev->xunmap.window;
1613+ break;
1614+ case MapNotify:
1615+ id = xev->xmap.window;
1616+ break;
1617+ case ConfigureNotify:
1618+ id = xev->xconfigure.window;
1619+ break;
1620+ case ConfigureRequest:
1621+ id = xev->xconfigurerequest.window;
1622+ break;
1623+ /* Garbagge collection !!!! am i losing prompt b/c of that? */
1624+ case CreateNotify: /* */
1625+ id = xev->xcreatewindow.window;
1626+ break;
1627+ case DestroyNotify:
1628+ id = xev->xdestroywindow.window;
1629+ /* premature here? */
1630+ break;
1631+ case MapRequest:
1632+ id = xev->xmaprequest.window;
1633+ break;
1634+ default:
1635+ id = xev->xany.window;
1636+ };
1637+ Lisp_Window *w = find_window_by_id (id)? : find_window_by_frame(id);
1638+
1639+ DB (("** Event: serial:%s%d%s: %s%s%s (event: %x win %x: %s)\n",
1640+ event_color, xev->xkey.serial, color_reset,
1641+ event_name_color,
1642+ xev->type < LASTEvent ? event_names[xev->type] : "unknown", color_reset,
1643+ event, id,
1644+ (w) ? rep_STR (w->name) : (u_char *)"unknown"));
1645+ }
1646+ } else {
1647+ /* give a small hint at the quantity.*/
1648+ DB(("%s%s%s", events_color,
1649+ (xev->xany.window == no_focus_window) ? "F":
1650+ (xev->xany.window == root_window) ? "R": "@", color_reset
1651+ )); /* @ */
1652+ }
1653+ };
1654+
1655+}
1656+
15181657 /* Handle all available X events matching event mask MASK. Or any events
15191658 if MASK is zero. */
15201659 void
@@ -1553,15 +1692,7 @@ handle_input_mask(long mask)
15531692 if (xev.type == NoExpose || xev.type == GraphicsExpose)
15541693 continue;
15551694
1556-#ifdef DEBUG
1557- do {
1558- Lisp_Window *w = find_window_by_id (xev.xany.window);
1559- DB(("** Event: %s (win %lx: %s)\n",
1560- xev.type < LASTEvent ? event_names[xev.type] : "unknown",
1561- (long)xev.xany.window, w ? (char *) rep_STR (w->name) : "unknown"));
1562- } while (0);
1563-#endif
1564-
1695+ report_event (&xev);
15651696 record_event_time (&xev);
15661697 current_x_event = &xev;
15671698 invalidate_cached_mouse_position ();
--- a/src/frames.c
+++ b/src/frames.c
@@ -43,6 +43,10 @@
4343 #include <X11/Xresource.h>
4444 #include <X11/extensions/shape.h>
4545 #include <assert.h>
46+#include "debug.h"
47+#include "debug-colors.h"
48+int debug_frames;
49+
4650
4751 static XID window_fp_context;
4852
@@ -1386,6 +1390,7 @@ build_frame_part (struct frame_part *fp)
13861390 else
13871391 fp->rendered_image = Qnil;
13881392
1393+ if (debug_frames)
13891394 DB((" part: x=%d y=%d width=%d height=%d\n",
13901395 fp->x, fp->y, fp->width, fp->height));
13911396
@@ -1502,6 +1507,7 @@ list_frame_generator (Lisp_Window *w)
15021507 else
15031508 right_x = bottom_y = 0;
15041509
1510+ if (debug_frames)
15051511 DB(("list_frame_generator(%s)\n", rep_STR(w->name)));
15061512
15071513 while (gen_list != Qnil && rep_SYMBOLP(gen_list) && !rep_INTERRUPTP)
@@ -1585,6 +1591,7 @@ list_frame_generator (Lisp_Window *w)
15851591 w->frame_x = left_x;
15861592 w->frame_y = top_y;
15871593
1594+ if (debug_frames)
15881595 DB((" bounding box: x=%d y=%d width=%d height=%d\n",
15891596 left_x, top_y, w->frame_width, w->frame_height));
15901597
@@ -1729,6 +1736,7 @@ restack_frame_parts (Lisp_Window *w)
17291736 void
17301737 create_window_frame (Lisp_Window *w)
17311738 {
1739+ if (debug_frames)
17321740 DB(("create_window_frame (%s)\n", rep_STR(w->name)));
17331741 if (w->frame_parts == 0)
17341742 {
--- a/src/functions.c
+++ b/src/functions.c
@@ -45,6 +45,10 @@
4545 #include <X11/Xatom.h>
4646 #include <stdint.h>
4747
48+#include "debug.h"
49+#include "debug-colors.h"
50+int debug_functions=0;
51+
4852 /* Number of outstanding server grabs made; only when this is zero is
4953 the server ungrabbed. */
5054 static int server_grabs;
@@ -85,12 +89,14 @@ windows isn't affected.
8589 repv ptr;
8690 Lisp_Window *pred;
8791
92+ /* check that it's a list of _windows_ */
8893 rep_DECLARE1(list, rep_LISTP);
8994 for (ptr = list; rep_CONSP (ptr); ptr = rep_CDR (ptr))
9095 {
9196 if (!WINDOWP (rep_CAR (ptr)))
9297 return rep_signal_arg_error (list, 1);
9398 }
99+ /* end of the check*/
94100
95101 if (list == Qnil)
96102 return Qt;
@@ -98,6 +104,8 @@ windows isn't affected.
98104 ptr = list;
99105 pred = 0;
100106
107+ if (debug_stacking)
108+ DB (("%s%s%s\n", functions_color, __FUNCTION__, color_reset));
101109 while (rep_CONSP (ptr))
102110 {
103111 Lisp_Window *this = VWIN (rep_CAR (ptr));
--- a/src/images.c
+++ b/src/images.c
@@ -50,6 +50,10 @@ static ImlibData *imlib_id;
5050 GdkInterpType interp_type = GDK_INTERP_BILINEAR;
5151 #endif
5252
53+#include "debug.h"
54+#include "debug-colors.h"
55+int debug_images = 0;
56+
5357 Colormap image_cmap;
5458 Visual *image_visual;
5559 int image_depth;
--- a/src/keys.c
+++ b/src/keys.c
@@ -27,6 +27,10 @@
2727 #include <X11/keysym.h>
2828 #include <X11/Xutil.h>
2929
30+#include "debug.h"
31+#include "debug-colors.h"
32+int debug_keys;
33+
3034 /* max number of milliseconds between successive-clicks */
3135 #define DEFAULT_DOUBLE_CLICK_TIME 250
3236
--- a/src/main.c
+++ b/src/main.c
@@ -487,6 +487,7 @@ where OPTIONS are any of:\n\
487487 Fset (Qfonts_are_fontsets, Qnil);
488488 }
489489
490+ set_init ();
490491 /* call all init funcs... */
491492 session_init ();
492493 events_init ();
--- /dev/null
+++ b/src/mmc.c
@@ -0,0 +1,608 @@
1+#include "sawfish.h"
2+#include <sys/resource.h>
3+#include <time.h>
4+
5+/* fixme: this assumes a 255-color xterm! */
6+
7+#ifdef USE_XKB
8+#include <X11/XKBlib.h> /* extensions/XKB.h */
9+#include <X11/extensions/XKBstr.h>
10+extern int usexkb;
11+#endif /* USE_XKB */
12+
13+#include <errno.h>
14+#include <assert.h>
15+
16+#include "debug.h"
17+#include "debug-colors.h"
18+
19+
20+const char*
21+window_name (Lisp_Window *w)
22+{
23+ /* todo: root_window or no_focus_window ? */
24+ repv name = (w)?(w->net_name != Qnil ? w->net_name : w->name) : NULL;
25+ /* stolen from window-name */
26+ return (name ? (char *) rep_STR(name) : (w?"unknown":"NULL"));
27+}
28+
29+const char*
30+window_name_id (Lisp_Window *w, Window id)
31+{
32+ if (w)
33+ return window_name(w);
34+ else
35+ return ((id == no_focus_window) ? "no_focus_window"
36+ : ((id == root_window) ? "Root_window" : "unknown"));
37+}
38+
39+/* mmc: make a nice string format from the Time T
40+ * only for debugging
41+ */
42+
43+char*
44+my_timestamp(Time t)
45+{
46+ static char buf[30]; /* like asctime */
47+
48+ /* fixme: non standard ?? */
49+ int sec= (int) t / 1000;
50+ int min= (int) sec / 60;
51+ int rest=(int) min / 60;
52+
53+ min= min % 60;
54+ sec= sec % 60;
55+
56+
57+
58+ sprintf(buf, "%s%u:%2u:%02u:%02lu%s",
59+ time_color,
60+ rest,
61+ min,
62+ sec,
63+ t % 1000, /* (t /10 ) */
64+ color_reset);
65+ return buf;
66+}
67+
68+/* a useless confirmation? */
69+bool
70+window_is_frame_part (Window id, Lisp_Window *w)
71+{
72+ struct frame_part* p = w->frame_parts;
73+ while (p != NULL)
74+ {
75+ if (p->id == id)
76+ return TRUE;
77+ p = p->next;
78+ }
79+ return FALSE;
80+}
81+
82+Lisp_Window *
83+find_window_by_frame (Window id)
84+{
85+ Lisp_Window *w;
86+
87+ w = window_list;
88+ while (w != 0 && w->frame != id)
89+ w = w->next;
90+ return w;
91+}
92+
93+
94+inline char*
95+window_relation_desc (Lisp_Window *w, Window id)
96+{
97+ return ((id == w->id)? "(" window_color "itself" color_reset ")" :
98+ ( (id == w->frame) ? "(" frame_window_color "frame" color_reset")" :
99+ (window_is_frame_part (id, w) ? "frame_part" : "??" )));
100+}
101+
102+
103+static char* focus_detail_names[]=
104+{
105+ "NotifyAncestor",
106+ "NotifyVirtual",
107+ "NotifyInferior",
108+ "NotifyNonlinear",
109+ "NotifyNonlinearVirtual",
110+ "NotifyPointer",
111+ "NotifyPointerRoot",
112+ "NotifyDetailNone"
113+};
114+
115+
116+char* focus_mode_string[] =
117+{
118+ /* taken from /usr/include/X11/X.h */
119+ "NotifyNormal",
120+ "NotifyGrab",
121+ "NotifyUngrab",
122+ "NotifyWhileGrabbed",
123+};
124+
125+char* buffer;
126+
127+#define color_fg(string, fg) (buffer = alloca(BUFFER_SIZE), \
128+ color_fg_string(string, fg, buffer))
129+
130+void
131+describe_focus_in(XEvent *ev,Lisp_Window *w)
132+{
133+ assert (ev->xfocus.detail < 8); /* what is 8? */
134+
135+ int color= ((ev->xfocus.mode) == NotifyGrab)?145:
136+ (((ev->xfocus.mode) == NotifyUngrab)?146:147);
137+
138+ DB (("%s%s received %lu win = %" FMT_WIN ":%s(%s) mode: %s%s%s detail: %s%s%s\n",
139+ color_fg("\x1b[38;5;",color),
140+ /* "%s received %d win = %s mode: %s detail:\n", */
141+ //(ev->xfocus.type == FocusIn)? "focus_in": "focus_out",
142+ __FUNCTION__,
143+
144+ ev->xfocus.serial,
145+ w->id,
146+ window_name_id (w, ev->xfocus.window),
147+ (w) ? window_relation_desc (w,ev->xfocus.window):"",
148+
149+ color_fg("\x1b[38;5;", 116+ev->xfocus.mode),
150+ (ev->xfocus.mode < sizeof(focus_mode_string)/sizeof(focus_mode_string[0])) ?
151+ focus_mode_string[ev->xfocus.mode]:"<unexpected>!",
152+ color_reset,
153+
154+ color_fg("\x1b[38;5;", color),
155+ /* focus_mode_color, */
156+ /* ev->xfocus.detail, */
157+ focus_detail_names[ev->xfocus.detail],
158+ color_reset));
159+}
160+
161+/*static */
162+void
163+describe_focus_out(XEvent *ev, Lisp_Window *w)
164+{
165+ if (!(ev->xfocus.detail < (sizeof(focus_detail_names) /sizeof(focus_detail_names[0]))))
166+ return;
167+
168+ if (!w)
169+ w = find_window_by_frame (ev->xfocus.window);
170+
171+ char* window_name = window_name_id (w,ev->xfocus.window);
172+ int color= ((ev->xfocus.mode) == NotifyGrab)? 36:
173+ (((ev->xfocus.mode) == NotifyUngrab)?34:33);
174+
175+ DB (("%s%s%s serial %lu win = %" FMT_WIN " %s(%s) mode: %s%s%s detail: %s%s%s\n", /* %d */
176+ /* "%s received %d win = %s mode: %s detail:\n", */
177+ color_fg("\x1b[38;5;",color),
178+ __FUNCTION__, // (ev->xfocus.type == FocusIn)? "focus_in": "focus_out",
179+ color_reset,
180+ ev->xfocus.serial,
181+ ev->xfocus.window,
182+ window_name,
183+ (w) ? window_relation_desc (w,ev->xfocus.window):"",
184+
185+ color_fg("\x1b[38;5;", 116 + ev->xfocus.mode),
186+ ((ev->xfocus.mode < sizeof(focus_mode_string)/sizeof(focus_mode_string[0]))?
187+ focus_mode_string[ev->xfocus.mode]:"<unexpected>!"),
188+ color_reset,
189+
190+ /* detail: */
191+ color_fg("\x1b[38;5;", color),
192+ focus_detail_names[ev->xfocus.detail], /* ev->xfocus.detail, */
193+ color_reset));
194+};
195+
196+extern int restack_fast;
197+int
198+set_int_variable(int* var, repv value)
199+{
200+ rep_DECLARE1 (value, rep_INTP);
201+
202+ int old=*var;
203+ *var = rep_INT(value);
204+ return rep_MAKE_INT(old);
205+}
206+
207+
208+/* mmc: i should add incrementing/decrementing & commit-on-zero? */
209+DEFUN("set-restack-fast", Fset_restack_fast, Sset_restack_fast, (repv debug), rep_Subr1) /*
210+::doc:sawfish.wm.events::set-restack-fast
211+make the following restacking operations immediate if 0, and posponed if 1
212+::end:: */
213+{
214+ rep_DECLARE1 (debug, rep_INTP);
215+ return set_int_variable(&restack_fast, debug);
216+}
217+
218+extern bool be_proactive_in_move;
219+
220+
221+#if 0
222+DEFUN("set-proactive-move", Fset_proactive_move, Sset_proactive_move, (repv debug), rep_Subr1) /*
223+::doc:sawfish.wm.events#set-proactive-move::
224+set-proactive-move 0/1
225+::end:: */
226+{
227+ rep_DECLARE1 (debug, rep_INTP);
228+ return set_int_variable(&be_proactive_in_move, debug);
229+}
230+#endif
231+
232+
233+DEFUN("set-debug-events", Fset_debug_events, Sset_debug_events, (repv debug), rep_Subr1) /*
234+::doc:sawfish.wm.events#set-debug-events::
235+set-debug-events 0/1
236+::end:: */
237+{
238+ rep_DECLARE1 (debug, rep_INTP);
239+ return set_int_variable(&debug_events, debug);
240+}
241+
242+DEFUN("set-debug-windows", Fset_debug_windows, Sset_debug_windows, (repv debug), rep_Subr1) /*
243+::doc:sawfish.wm.windows#set-debug-windows::
244+set-debug-windows 0/1
245+::end:: */
246+{
247+ rep_DECLARE1 (debug, rep_INTP);
248+ return set_int_variable(&debug_windows, debug);
249+}
250+
251+
252+DEFUN("set-debug-keys", Fset_debug_keys, Sset_debug_keys, (repv debug), rep_Subr1) /*
253+::doc:sawfish.wm.events::set-debug-keys
254+set-debug-keys 0/1
255+::end:: */
256+{
257+ rep_DECLARE1 (debug, rep_INTP);
258+ return set_int_variable(&debug_keys, debug);
259+}
260+
261+DEFUN("set-debug-stacking", Fset_debug_stacking, Sset_debug_stacking, (repv debug), rep_Subr1) /*
262+::doc:sawfish.wm.events::set-debug-keys
263+set-debug-keys 0/1
264+::end:: */
265+{
266+ rep_DECLARE1 (debug, rep_INTP);
267+ return set_int_variable(&debug_stacking, debug);
268+}
269+
270+
271+#ifdef USE_XKB
272+/* work-in-progress? */
273+DEFUN("set-xkb-event-mask", Fset_xkb_event_mask, Sset_xkb_event_mask, (repv mask, repv value), rep_Subr2) /*
274+::doc:sawfish.wm.events::set-debug-keys
275+set-debug-keys 0/1
276+::end:: */
277+{
278+ rep_DECLARE1 (mask, rep_INTP);
279+ rep_DECLARE2 (value, rep_INTP);
280+
281+ if (usexkb)
282+ /* i want to report them. */
283+ XkbSelectEvents(dpy, XkbUseCoreKbd, rep_INT(mask), rep_INT(value)); /* `set' */
284+/* XkbSelectEventsDetails(dpy, XkbUseCoreKbd, XkbMapNotifyMask, XkbMapNotifyMask); `set' */
285+/* return set_int_variable(&xallowevents_handling, debug); */
286+ return Qnil;
287+}
288+
289+
290+#endif
291+
292+
293+
294+DEFUN("set-debug-functions", Fset_debug_functions, Sset_debug_functions, (repv debug), rep_Subr1) /*
295+::doc:sawfish.wm.events::set-debug-functions
296+set-debug-functions 0/1
297+::end:: */
298+{
299+ rep_DECLARE1 (debug, rep_INTP);
300+ return set_int_variable(&debug_functions, debug);
301+}
302+
303+
304+DEFUN("set-debug-display", Fset_debug_display, Sset_debug_display, (repv debug), rep_Subr1) /*
305+::doc:sawfish.wm.events::set-debug-display
306+set-debug-display 0/1
307+::end:: */
308+{
309+ rep_DECLARE1 (debug, rep_INTP);
310+ return set_int_variable(&debug_display, debug);
311+}
312+
313+
314+DEFUN("set-debug-images", Fset_debug_images, Sset_debug_images, (repv debug), rep_Subr1) /*
315+::doc:sawfish.wm.events::set-debug-images
316+set-debug-images 0/1
317+::end:: */
318+{
319+ rep_DECLARE1 (debug, rep_INTP);
320+ return set_int_variable(&debug_images, debug);
321+}
322+
323+DEFUN("set-debug-cache", Fset_debug_cache, Sset_debug_cache, (repv debug), rep_Subr1) /*
324+::doc:sawfish.wm.events::set-debug-cache
325+set-debug-cache 0/1
326+::end:: */
327+{
328+ rep_DECLARE1 (debug, rep_INTP);
329+ return set_int_variable(&debug_cache, debug);
330+}
331+
332+#if 0
333+DEFUN("set-grab-owner", Fset_grab_owner, Sset_grab_owner, (repv owner), rep_Subr1) /*
334+::doc:sawfish.wm.events::set-debug-display
335+set-debug-display 0/1
336+::end:: */
337+{
338+ rep_DECLARE1 (owner, rep_INTP); /* fixme: should be boolean! */
339+ return set_int_variable(&default_grab_owner, owner);
340+}
341+#endif
342+
343+DEFUN("next-request", Fnext_request, Snext_request, (void), rep_Subr0) /*
344+::doc:sawfish.wm.events::next-request
345+next-request
346+::end:: */
347+{
348+ return rep_MAKE_INT(NextRequest(dpy));
349+}
350+
351+DEFUN("set-debug-frames", Fset_debug_frames, Sset_debug_frames, (repv debug), rep_Subr1) /*
352+::doc:sawfish.wm.events::set-debug-frames
353+set-debug-frames 0/1
354+::end:: */
355+{
356+ rep_DECLARE1 (debug, rep_INTP);
357+ return set_int_variable(&debug_frames, debug);
358+}
359+
360+#if 0
361+DEFUN("set-debug-frame-part", Fset_debug_frame_part, Sset_debug_frame_part, (repv debug), rep_Subr1) /*
362+::doc:sawfish.wm.events::set-debug-frames
363+set-debug-frames 0/1
364+::end:: */
365+{
366+ rep_DECLARE1 (debug, rep_INTP);
367+ return set_int_variable(&debug_frame_part, debug);
368+}
369+
370+
371+DEFUN("set-dont-allow-events", Fset_dont_allow_events, Sset_dont_allow_events, (repv debug), rep_Subr1) /*
372+::doc:sawfish.wm.events::set-dont-allow-event
373+::set-dont-allow-event 0/1
374+::end:: */
375+{
376+ rep_DECLARE1 (debug, rep_INTP);
377+ DB(("set-dont-allow-events %d -> %d (now)\n", dont_allow_events, rep_INT(debug)));
378+ return set_int_variable(&dont_allow_events, debug);
379+}
380+#endif
381+
382+int frame_options;
383+
384+DEFUN("set-frame-options", Fset_frame_options, Sset_frame_options, (repv debug), rep_Subr1) /*
385+::doc:sawfish.wm.events::set-frame-options
386+set-frame-options 0/1
387+::end:: */
388+{
389+ rep_DECLARE1 (debug, rep_INTP);
390+ return set_int_variable(&frame_options, debug);
391+}
392+
393+
394+
395+int window_options;
396+
397+DEFUN("set-window-options", Fset_window_options, Sset_window_options, (repv debug), rep_Subr1) /*
398+::doc:sawfish.wm.events::set-frame-options
399+set-frame-options 0/1
400+::end:: */
401+{
402+ rep_DECLARE1 (debug, rep_INTP);
403+ return set_int_variable(&window_options, debug);
404+}
405+
406+
407+
408+
409+/* Run external program w/ UID (su)
410+ * set & get priority.
411+ * */
412+
413+DEFUN("get-priority", Fget_priority, Sget_priority, (repv which, repv who), rep_Subr2) /*
414+::doc:sawfish.wm.events::set-debug-display
415+(get-priority 0 0) to get the sawfish WM process's priority.
416+::end:: */
417+{
418+ rep_DECLARE1(which, rep_INTP);
419+ rep_DECLARE2(who, rep_INTP);
420+
421+#if 0
422+enum __priority_which
423+{
424+ PRIO_PROCESS = 0, /* WHO is a process ID. */
425+#define PRIO_PROCESS PRIO_PROCESS
426+ PRIO_PGRP = 1, /* WHO is a process group ID. */
427+#define PRIO_PGRP PRIO_PGRP
428+ PRIO_USER = 2 /* WHO is a user ID. */
429+#define PRIO_USER PRIO_USER
430+};
431+#endif
432+
433+
434+
435+ int c_which = rep_INT(which);
436+ if ((c_which == PRIO_PROCESS)
437+ || (c_which == PRIO_PGRP)
438+ || (c_which == PRIO_USER))
439+ {
440+ /* Since getpriority() can legitimately return the value -1, it is necessary to clear the
441+ external variable errno prior to the call */
442+ errno = 0;
443+ int res = getpriority(c_which, rep_INT(who));
444+
445+ if ((res == -1) && errno)
446+ {
447+ /* throw error! */
448+ return rep_FALSE;
449+ /* rep_handle_error */
450+ return rep_signal_arg_error(which, 0);
451+ }
452+ else
453+ {
454+ return rep_MAKE_INT(res);
455+ }
456+ }
457+ else return rep_signal_arg_error(which, 0);
458+}
459+
460+
461+
462+
463+static repv
464+reopen_stdio_stream(FILE** pointer, char* filename)
465+{
466+ /* can access? */
467+ /* FILE* */
468+ FILE* result = freopen(filename, "a", *pointer);
469+ if (result){
470+
471+ /* setlinebuf(result); */
472+ setvbuf(result, (char *)NULL, _IONBF, 0);
473+ } else
474+ {
475+ /*disaster!!! */
476+ XBell(dpy,0);
477+ result = freopen("/dev/null", "a", *pointer);
478+ };
479+ assert(result);
480+
481+ *pointer = result;
482+ DB(("%s: %s %d\n", __FUNCTION__, result?"ok":"error!", result?fileno(result):-1));
483+ return result?rep_TRUE:rep_FALSE;
484+}
485+
486+
487+
488+
489+
490+
491+DEFUN("reopen-stderr", Freopen_stderr, Sreopen_stderr, (repv filename), rep_Subr1) /*
492+::doc:sawfish.wm.events::reopen-stderr
493+redirect-stderr-to filename
494+::end:: */
495+{
496+ rep_DECLARE1(filename, rep_STRINGP);
497+
498+ FILE **stdio_stream = &stderr;
499+
500+ repv result = reopen_stdio_stream (&stderr, rep_STR(filename));
501+
502+ repv stream = Fstderr_file();
503+ rep_FILE(stream)->file.fh = *stdio_stream;
504+ return result?rep_TRUE:rep_FALSE;
505+}
506+
507+
508+DEFUN("reopen-stdout", Freopen_stdout, Sreopen_stdout, (repv filename), rep_Subr1) /*
509+::doc:sawfish.wm.events::reopen-stdout
510+redirect-stdout-to filename
511+::end:: */
512+{
513+ rep_DECLARE1(filename, rep_STRINGP);
514+
515+ FILE **stdio_stream = &stdout;
516+ repv result = reopen_stdio_stream (stdio_stream, rep_STR(filename));
517+
518+ repv stream = Fstdout_file();
519+ rep_FILE(stream)->file.fh = *stdio_stream;
520+ return result?rep_TRUE:rep_FALSE;
521+}
522+
523+
524+
525+#if 0
526+bool
527+reopen_lisp_stream(repv stream, char* filename)
528+{
529+ /* assert (stream_p()) */
530+ FILE **stdio_stream = &(rep_FILE(stream)->file.fh); /* ??? */
531+ /* if (*strio_stream) */
532+ repv result = reopen_stdio_stream (stdio_stream, rep_STR(filename));
533+ rep_FILE(stream)->file.fh = *stdio_stream;
534+}
535+
536+
537+
538+reopen_lisp_stream(Fstdout_file());
539+#endif
540+
541+static int
542+get_int_variable_from_env(char* name, int* variable)
543+{
544+ if (getenv(name) != NULL)
545+ {
546+ *variable = atoi(getenv(name));
547+ DB(("using the ENV VAR $%s = %s -> %d\n", name, getenv(name), *variable));
548+ return *variable;
549+ }
550+ return 0;
551+}
552+
553+
554+void
555+set_init (void)
556+{
557+ repv tem;
558+
559+ tem = rep_push_structure ("sawfish.wm.windows.subrs");
560+
561+
562+ /* rep_ADD_SUBR(Sstart_restacking); */
563+ rep_ADD_SUBR(Sreopen_stderr);
564+ rep_ADD_SUBR(Sreopen_stdout);
565+
566+ rep_ADD_SUBR(Sget_priority);
567+ rep_ADD_SUBR(Sset_restack_fast);
568+
569+ rep_ADD_SUBR(Sset_debug_functions);
570+ rep_ADD_SUBR(Sset_debug_display);
571+ rep_ADD_SUBR(Sset_debug_images);
572+ rep_ADD_SUBR(Sset_debug_cache);
573+
574+ rep_ADD_SUBR(Snext_request);
575+ rep_pop_structure (tem);
576+
577+ tem = rep_push_structure ("sawfish.wm.events");
578+#if 0
579+ rep_ADD_SUBR(Sset_grab_owner);
580+ rep_ADD_SUBR(Sset_dont_allow_events);
581+ rep_ADD_SUBR(Sset_debug_frame_part);
582+ rep_ADD_SUBR(Sset_frame_options);
583+ rep_ADD_SUBR(Sset_window_options);
584+ rep_ADD_SUBR(Sset_xkb_event_mask);
585+ rep_ADD_SUBR(Sset_proactive_move);
586+
587+ rep_INTERN_SPECIAL(debug_events);
588+ Fset (Qdebug_events, rep_MAKE_INT(0));
589+ rep_ADD_SUBR(Sset_xallowevents_handling);
590+#endif
591+ rep_ADD_SUBR(Sset_debug_events);
592+ rep_ADD_SUBR(Sset_debug_windows);
593+ rep_ADD_SUBR(Sset_debug_keys);
594+ rep_ADD_SUBR(Sset_debug_stacking);
595+
596+ rep_ADD_SUBR(Sset_debug_frames);
597+
598+ rep_pop_structure (tem);
599+
600+ /* initial debug. */
601+ get_int_variable_from_env("SAWFISH_DEBUG_STACKING", &debug_stacking);
602+ get_int_variable_from_env("SAWFISH_DEBUG_WINDOWS", &debug_windows);
603+ get_int_variable_from_env("SAWFISH_DEBUG_FUNCTIONS", &debug_functions);
604+
605+ get_int_variable_from_env("SAWFISH_DEBUG_EVENTS", &debug_events);
606+ get_int_variable_from_env("SAWFISH_DEBUG_KEYS", &debug_keys);
607+ get_int_variable_from_env("SAWFISH_DEBUG_FRAMES", &debug_frames);
608+}
--- a/src/pixmap-cache.c
+++ b/src/pixmap-cache.c
@@ -42,6 +42,10 @@
4242 static unsigned long cached_pixels, max_cached_pixels = 64 * 1024;
4343 static unsigned long hits, misses;
4444
45+#include "debug.h"
46+#include "debug-colors.h"
47+int debug_cache;
48+
4549 #ifdef NEED_PIXMAP_CACHE
4650
4751 struct pixmap_cache_node_struct {
@@ -144,12 +148,16 @@ pixmap_cache_ref (Lisp_Image *im, int width, int height,
144148 remove_from_age_list (n);
145149 prepend_to_age_list (n);
146150 n->ref_count++;
151+ if (debug_cache & DB_CACHE_REF)
152+ DB(("%s now: %d\n", __FUNCTION__, n->ref_count));
147153 *p1 = n->p1;
148154 *p2 = n->p2;
149155 hits++;
150156 return TRUE;
151157 }
152158 }
159+ if (debug_cache & DB_CACHE_MISS)
160+ DB(("%s missed!\n", __FUNCTION__));
153161 misses++;
154162 return FALSE;
155163 }
@@ -163,6 +171,8 @@ pixmap_cache_unref (Lisp_Image *im, Pixmap p1, Pixmap p2)
163171 if (n->p1 == p1 && n->p2 == p2)
164172 {
165173 n->ref_count--;
174+ if (debug_cache & DB_CACHE_REF)
175+ DB(("%s remain %d\n", __FUNCTION__, n->ref_count));
166176 #ifdef DISABLE_CACHE
167177 if (n->ref_count == 0)
168178 delete_node (n, TRUE);
@@ -170,6 +180,8 @@ pixmap_cache_unref (Lisp_Image *im, Pixmap p1, Pixmap p2)
170180 return;
171181 }
172182 }
183+ if (debug_cache)
184+ DB(("%s\n", __FUNCTION__));
173185 fprintf (stderr, "warning: unref'ing unknown image in pixmap-cache\n");
174186 }
175187
@@ -179,7 +191,9 @@ pixmap_cache_set (Lisp_Image *im, int width, int height,
179191 {
180192 int pixel_count = width * height;
181193 pixmap_cache_node *n = 0;
194+ int deleted = 0;
182195
196+ /* shring the cache: */
183197 while (pixel_count + cached_pixels > max_cached_pixels)
184198 {
185199 /* remove oldest node */
@@ -189,9 +203,12 @@ pixmap_cache_set (Lisp_Image *im, int width, int height,
189203 if (this == 0)
190204 break;
191205 delete_node (this, n != 0);
206+ ++deleted;
192207 if (n == 0)
193208 n = this;
194209 }
210+ if (debug_cache & DB_CACHE_DELETE)
211+ DB(("%s had to delete %d nodes.\n", __FUNCTION__, deleted));
195212
196213 if (n == 0)
197214 n = rep_alloc (sizeof (pixmap_cache_node));
@@ -212,6 +229,8 @@ void
212229 pixmap_cache_flush_image (Lisp_Image *im)
213230 {
214231 pixmap_cache_node *n, *next;
232+ if (debug_cache)
233+ DB(("%s %p\n", __FUNCTION__, im));
215234 for (n = im->pixmap_first; n != 0; n = next)
216235 {
217236 next = n->next;
--- a/src/property-cache.c
+++ b/src/property-cache.c
@@ -50,20 +50,16 @@ property_cache_ref (repv id, repv prop)
5050
5151 h = CACHE_HASH (id, prop) * CACHE_ASSOC;
5252
53- DB (("prop ref: 0x%x,%s (%d) -> ", id, rep_STR (rep_SYM (prop)->name), h));
54-
5553 for (i = h; i < h + CACHE_ASSOC; i++)
5654 {
5755 if (cache_ids[i] == id && cache_props[i] == prop)
5856 {
5957 cache_hits++;
60- DB (("hit\n"));
6158 cache_ages[i] = ++cache_clock;
6259 return cache_values[i];
6360 }
6461 }
6562
66- DB (("miss\n"));
6763 cache_misses++;
6864 return rep_NULL;
6965 }
@@ -106,16 +102,11 @@ property_cache_set (repv id, repv prop, repv value, int invals)
106102
107103 assert (oldest != -1);
108104
109- if (cache_ids[oldest] != 0)
110- DB (("prop eject: 0x%x (%d)\n", cache_ids[oldest], oldest));
111-
112105 cache_ids[oldest] = id;
113106 cache_props[oldest] = prop;
114107 cache_values[oldest] = value;
115108 cache_ages[oldest] = ++cache_clock;
116109 cache_updates[oldest] = invals;
117-
118- DB (("set: 0x%x,%s (%d)\n", id, rep_STR (rep_SYM (prop)->name), oldest));
119110 }
120111
121112 void
--- a/src/sawfish_subrs.h
+++ b/src/sawfish_subrs.h
@@ -58,6 +58,7 @@ extern Window root_window, no_focus_window;
5858 extern Atom xa_wm_state, xa_wm_change_state, xa_wm_protocols,
5959 xa_wm_delete_window, xa_wm_colormap_windows, xa_wm_take_focus,
6060 xa_compound_text, xa_wm_net_name, xa_wm_net_icon_name, xa_utf8_string;
61+extern Atom ignore_atoms[2]; /* _WIN_AREA _WIN_WORKSPACE */
6162 extern int shape_event_base, shape_error_base;
6263 extern repv Qdisplay_name, Qcanonical_display_name;
6364 extern bool sys_init (char *program_name);
@@ -367,4 +368,14 @@ extern void insert_in_stacking_list_below (Lisp_Window *w, Lisp_Window *x);
367368 extern void restack_window (Lisp_Window *w);
368369 extern repv make_stacking_list (void);
369370
371+/* from mmc.c */
372+extern const char* window_name (Lisp_Window *w);
373+extern const char* window_name_id (Lisp_Window *w, Window id);
374+extern char* my_timestamp(Time t);
375+extern void describe_focus_out(XEvent *ev, Lisp_Window *w);
376+extern void describe_focus_in(XEvent *ev,Lisp_Window *w);
377+
378+extern void set_init (void);
379+
380+
370381 #endif /* SAWFISH_SUBRS_H */
--- a/src/stacking-list.c
+++ b/src/stacking-list.c
@@ -24,6 +24,10 @@
2424
2525 #include "sawfish.h"
2626 #include <assert.h>
27+#include "debug.h"
28+#include "debug-colors.h"
29+int debug_stacking;
30+
2731
2832 static Lisp_Window *lowest_window, *highest_window;
2933
--- a/src/windows.c
+++ b/src/windows.c
@@ -25,6 +25,11 @@
2525 #include <X11/extensions/shape.h>
2626 #include <glib.h>
2727
28+#include "debug.h"
29+#include "debug-colors.h"
30+int debug_windows;
31+
32+
2833 Lisp_Window *window_list;
2934 int window_type;
3035
@@ -105,6 +110,10 @@ mapped_not_override_p (Window id)
105110 XWindowAttributes wa;
106111
107112 XGetWindowAttributes(dpy, id, &wa);
113+ if (debug_windows & DB_WINDOWS_REST)
114+ DB (("%s %" FMT_WIN " %s %s\n", __FUNCTION__, id,
115+ (wa.map_state == IsUnmapped)?"is unmapped!":"",
116+ (wa.override_redirect == True)?"has override!":""));
108117 return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
109118 }
110119
@@ -136,7 +145,7 @@ commit_queued_focus_change (void)
136145 {
137146 if (queued_take_focus)
138147 {
139- DB((" sending WM_TAKE_FOCUS %x %ld\n",
148+ DB((" sending WM_TAKE_FOCUS %" FMT_WIN " %ld\n",
140149 (unsigned) queued_focus_id, queued_focus_time));
141150
142151 focus_request.sent = True;
@@ -154,7 +163,7 @@ commit_queued_focus_change (void)
154163 }
155164 if (queued_set_focus)
156165 {
157- DB((" focusing %x %ld\n",
166+ DB((" focusing %" FMT_WIN " %ld\n",
158167 (unsigned) queued_focus_id, queued_focus_time));
159168 XSetInputFocus (dpy, queued_focus_id,
160169 queued_focus_revert, queued_focus_time);
@@ -236,6 +245,8 @@ get_window_protocols (Lisp_Window *w)
236245 int n;
237246 w->does_wm_take_focus = 0;
238247 w->does_wm_delete_window = 0;
248+ if (debug_windows & DB_WINDOWS_REST)
249+ DB (("W: %s: %s\n",__FUNCTION__,rep_STR(w->name)));
239250 if (XGetWMProtocols (dpy, w->id, &prot, &n) != 0)
240251 {
241252 int i;
@@ -244,12 +255,14 @@ get_window_protocols (Lisp_Window *w)
244255 if (prot[i] == xa_wm_take_focus)
245256 {
246257 w->does_wm_take_focus = 1;
247- DB((" WM_TAKE_FOCUS is set\n"));
258+ if (debug_windows & DB_WINDOWS_PROT)
259+ DB (("W: WM_TAKE_FOCUS is set\n"));
248260 }
249261 if (prot[i] == xa_wm_delete_window)
250262 {
251263 w->does_wm_delete_window = 1;
252- DB((" WM_DELETE_WINDOW is set\n"));
264+ if (debug_windows & DB_WINDOWS_PROT)
265+ DB (("W: WM_DELETE_WINDOW is set\n"));
253266 }
254267 }
255268 XFree (prot);
@@ -284,6 +297,8 @@ find_window_by_id (Window id)
284297 {
285298 Lisp_Window *w;
286299 w = window_list;
300+ if (debug_windows & DB_WINDOWS_FIND)
301+ DB(("%s searching for %" FMT_WIN "\n", __FUNCTION__, id));
287302 while (w != 0 && w->id != id && w->frame != id)
288303 w = w->next;
289304 return w;
@@ -292,7 +307,8 @@ find_window_by_id (Window id)
292307 void
293308 install_window_frame (Lisp_Window *w)
294309 {
295- DB(("install_window_frame (%s)\n", rep_STR(w->name)));
310+ if ((debug_windows & DB_WINDOWS_FRAME) || debug_frames)
311+ DB (("%s%s%s on %s\n", reparent_color,__FUNCTION__, color_reset, rep_STR(w->name)));
296312 if (!w->reparented && w->frame != 0 && !WINDOW_IS_GONE_P (w))
297313 {
298314 XSetWindowAttributes wa;
@@ -300,6 +316,9 @@ install_window_frame (Lisp_Window *w)
300316 XSelectInput (dpy, w->frame, FRAME_EVENTS);
301317
302318 before_local_map (w);
319+ if (debug_windows & DB_WINDOWS_FRAME)
320+ DB(("%sXReparentWindow: %" FMT_WIN " %s -> %" FMT_WIN "%s\n", reparent_color,
321+ w->id, rep_STR(w->name), w->frame, color_reset));
303322 XReparentWindow (dpy, w->id, w->frame, -w->frame_x, -w->frame_y);
304323 w->reparented = TRUE;
305324 after_local_map (w);
@@ -315,16 +334,18 @@ install_window_frame (Lisp_Window *w)
315334 wa.win_gravity = StaticGravity;
316335 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
317336
318- DB((" reparented to %lx [%dx%d%+d%+d]\n",
319- w->frame, w->frame_width, w->frame_height,
320- w->frame_x, w->frame_y));
337+ if (debug_windows & DB_WINDOWS_FRAME)
338+ DB((" reparented to %" FMT_WIN " [%dx%d%+d%+d]\n",
339+ w->frame, w->frame_width, w->frame_height,
340+ w->frame_x, w->frame_y));
321341 }
322342 }
323343
324344 void
325345 remove_window_frame (Lisp_Window *w, bool restack)
326346 {
327- DB(("remove_window_frame (%s)\n", rep_STR(w->name)));
347+ if (debug_windows & DB_WINDOWS_FRAME)
348+ DB (("%s%s%s %s\n", reparent_color, __FUNCTION__, color_reset, rep_STR(w->name)));
328349 if (w->reparented && !WINDOW_IS_GONE_P (w))
329350 {
330351 XSetWindowAttributes wa;
@@ -334,6 +355,8 @@ remove_window_frame (Lisp_Window *w, bool restack)
334355 wa.win_gravity = w->attr.win_gravity;
335356 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
336357
358+ DB(("%sXReparentWindow: %" FMT_WIN " %s%s -> root_window at %s%d,%d%s\n", reparent_color,
359+ w->id, rep_STR(w->name), color_reset, reparent_color, w->attr.x, w->attr.y, color_reset));
337360 before_local_map (w);
338361 XReparentWindow (dpy, w->id, root_window, w->attr.x, w->attr.y);
339362 w->reparented = FALSE;
@@ -346,6 +369,9 @@ remove_window_frame (Lisp_Window *w, bool restack)
346369
347370 if (!w->mapped)
348371 XRemoveFromSaveSet (dpy, w->id);
372+ } else {
373+ if (debug_windows & DB_WINDOWS_FRAME)
374+ DB (("%s: window is gone, or reparented outside, doing nothing\n", __FUNCTION__));
349375 }
350376 }
351377
@@ -422,6 +448,13 @@ Lisp_Window *
422448 add_window (Window id)
423449 {
424450 Lisp_Window *w = rep_ALLOC_CELL(sizeof (Lisp_Window));
451+
452+ if (debug_windows & DB_WINDOWS_ADD) {
453+ if (id == root_window)
454+ DB (("W: add_window (ROOT)\n"));
455+ else
456+ DB (("W: add_window (%" FMT_WIN ")\n", id));
457+ };
425458 if (w != 0)
426459 {
427460 rep_GC_root gc_win;
@@ -430,11 +463,6 @@ add_window (Window id)
430463 unsigned int xwcm;
431464 long supplied;
432465
433- DB(("add_window (%lx)\n", id));
434-
435- if (id == root_window)
436- DB((" ** adding root window!?\n"));
437-
438466 rep_data_after_gc += sizeof (Lisp_Window);
439467 memset (w, 0, sizeof (Lisp_Window));
440468
@@ -491,9 +519,10 @@ add_window (Window id)
491519 w->shaped = bounding ? 1 : 0;
492520 }
493521
494- DB((" name=`%s' x=%d y=%d width=%d height=%d\n",
495- rep_STR(w->name), w->attr.x, w->attr.y,
496- w->attr.width, w->attr.height));
522+ if (debug_windows & DB_WINDOWS_ADD)
523+ DB (("W: name=`%s' x=%d y=%d width=%d height=%d\n",
524+ rep_STR(w->name), w->attr.x, w->attr.y,
525+ w->attr.width, w->attr.height));
497526
498527 xwcm = CWX | CWX | CWWidth | CWHeight | CWBorderWidth;
499528 xwc.x = w->attr.x;
@@ -725,6 +754,11 @@ Note that these are Lisp properties not X properties.
725754 {
726755 repv plist;
727756 rep_DECLARE1(win, XWINDOWP);
757+ if (debug_windows & DB_WINDOWS_PUT){
758+ DB(("%s %s prop: %s\n", __FUNCTION__, rep_STR(VWIN(win)->name),
759+ rep_SYMBOLP(prop)? (char*)rep_STR(rep_SYM(prop)->name):"not a symbol"));
760+ /* Fbacktrace(Fstderr_file()); //Fbacktrace(Qnil);*/
761+ }
728762 plist = VWIN(win)->plist;
729763 while (rep_CONSP(plist) && rep_CONSP(rep_CDR(plist)))
730764 {
@@ -873,6 +907,12 @@ new frame constructed as specified by FRAME.
873907 {
874908 rep_DECLARE1(win, WINDOWP);
875909 rep_DECLARE2(frame, rep_LISTP);
910+
911+ if (debug_frames && debug_windows) {
912+ DB(("%s:%s\n", __FUNCTION__, rep_STR(VWIN(win)->name)));
913+ Fbacktrace(Fstderr_file());
914+ }
915+
876916 Fgrab_server ();
877917
878918 if (VWIN(win)->reparented)
@@ -898,6 +938,11 @@ Reinitialises and recalibrates the window frame of WINDOW.
898938 rep_DECLARE1(win, WINDOWP);
899939 if (VWIN(win)->frame != 0 && VWIN(win)->rebuild_frame != 0)
900940 {
941+ if (debug_frames || (debug_windows & DB_WINDOWS_FRAME))
942+ DB(("%s: %s->rebuild_frame %d %d\n", __FUNCTION__,
943+ rep_STR(VWIN(win)->name),
944+ VWIN(win)->attr.width,VWIN(win)->attr.height));
945+
901946 VWIN(win)->rebuild_frame (VWIN(win));
902947 refresh_frame_parts (VWIN(win));
903948 Fcall_window_hook (Qafter_framing_hook, win, Qnil, Qnil);
@@ -1362,6 +1407,8 @@ description of HOOK-TYPE.
13621407 tem = Fwindow_get (win, hook, Qnil);
13631408 if (tem && tem != Qnil)
13641409 {
1410+ if (debug_windows & DB_WINDOWS_HOOKS)
1411+ DB (("W: call-window-hook: private %s\n", window_name (VWIN(win))));
13651412 tem = Fcall_hook (tem, args, type);
13661413 if (!tem || (type == Qand && tem == Qnil)
13671414 || (type == Qor && tem != Qnil))
@@ -1369,7 +1416,11 @@ description of HOOK-TYPE.
13691416 goto out;
13701417 }
13711418 }
1419+ if (debug_windows & DB_WINDOWS_HOOKS)
1420+ DB (("W: call-window-hook: public %s\n", window_name (VWIN(win))));
13721421 tem = Fcall_hook (hook, args, type);
1422+ if (debug_windows & DB_WINDOWS_HOOKS)
1423+ DB (("W: call-window-hook: end %s\n", window_name (VWIN(win))));
13731424 out:
13741425 rep_POPGC; rep_POPGC; rep_POPGC;
13751426 return tem;
@@ -1522,16 +1573,22 @@ static void
15221573 window_prin (repv stream, repv win)
15231574 {
15241575 char buf[128];
1525- sprintf (buf, "#<window %lx>", VWIN(win)->id);
1576+ snprintf (buf, sizeof(buf), "#<window %" FMT_WIN " %s>", VWIN(win)->id, rep_STR(VWIN(win)->name));
15261577 rep_stream_puts (stream, buf, -1, FALSE);
15271578 }
15281579
15291580 static void
15301581 window_mark (repv win)
15311582 {
1583+ if (debug_windows & DB_WINDOWS_GC)
1584+ DB(("%s: %p %s\n", __FUNCTION__, (void*) win, rep_STR(VWIN(win)->name)));
15321585 rep_MARKVAL(VWIN(win)->plist);
15331586 rep_MARKVAL(VWIN(win)->frame_style);
1587+ if (debug_windows & DB_WINDOWS_GC)
1588+ DB(("%s: now frame parts\n", __FUNCTION__));
15341589 mark_frame_parts (VWIN(win));
1590+ if (debug_windows & DB_WINDOWS_GC)
1591+ DB(("%s: now strings\n", __FUNCTION__));
15351592 rep_MARKVAL(VWIN(win)->name);
15361593 rep_MARKVAL(VWIN(win)->full_name);
15371594 rep_MARKVAL(VWIN(win)->icon_name);
@@ -1550,6 +1607,10 @@ window_mark_type (void)
15501607 // !(a || b) || ! b = ! (a || b && b)
15511608 if (! (w->destroyed && (w->id == 0))) // (!WINDOW_IS_GONE_P (w) || !w->destroyed)
15521609 rep_MARKVAL(rep_VAL(w));
1610+ else
1611+ if (debug_windows & DB_WINDOWS_GC)
1612+ DB(("%s: %snot marking%s %p %s\n", __FUNCTION__, warning_color, color_reset,
1613+ w, rep_STR(w->name)));
15531614 }
15541615 for (ph = prop_handlers; ph != 0; ph = ph->next)
15551616 rep_MARKVAL (ph->prop);
@@ -1560,12 +1621,17 @@ static void
15601621 window_sweep (void)
15611622 {
15621623 Lisp_Window **ptr = &window_list;
1624+
1625+ if (debug_windows & DB_WINDOWS_GC)
1626+ DB(("%s\n", __FUNCTION__));
15631627 while (*ptr != 0)
15641628 {
15651629 Lisp_Window *w = *ptr;
15661630 if (!rep_GC_CELL_MARKEDP(rep_VAL(w)))
15671631 {
15681632 assert (!window_in_stacking_list_p (w));
1633+ if (debug_windows & DB_WINDOWS_GC)
1634+ DB(("%s another window gone pointer: %p\n", __FUNCTION__, w));
15691635 destroy_window_frame (w, FALSE);
15701636 if (w->wmhints != 0)
15711637 XFree (w->wmhints);
@@ -1580,6 +1646,8 @@ window_sweep (void)
15801646 rep_GC_CLR_CELL(rep_VAL(w));
15811647 }
15821648 }
1649+ if (debug_windows & DB_WINDOWS_GC)
1650+ DB(("%s END\n", __FUNCTION__));
15831651 }
15841652
15851653 /* initialisation */
@@ -1591,6 +1659,8 @@ manage_windows (void)
15911659 unsigned int nchildren, i;
15921660 int revert_to;
15931661
1662+ if (debug_windows & DB_WINDOWS_REST)
1663+ DB(("%s\n", __FUNCTION__));
15941664 Fgrab_server ();
15951665
15961666 XGetInputFocus (dpy, &focus, &revert_to);
@@ -1610,8 +1680,13 @@ manage_windows (void)
16101680 }
16111681 focus = child;
16121682 }
1683+ else if (debug_windows & DB_WINDOWS_REST)
1684+ DB(("%s: (focus != PointerRoot)\n", __FUNCTION__));
16131685
16141686 XQueryTree (dpy, root_window, &root, &parent, &children, &nchildren);
1687+ if (debug_windows & DB_WINDOWS_REST)
1688+ DB(("%s: XQueryTree returned %d children\n",__FUNCTION__, nchildren));
1689+
16151690 initialising = TRUE;
16161691 for (i = 0; i < nchildren; i++)
16171692 {
--- a/src/x.c
+++ b/src/x.c
@@ -50,6 +50,9 @@
5050
5151 static int have_dbe;
5252
53+#include "debug.h"
54+#include "debug-colors.h"
55+
5356 /* An allocated x-gc */
5457 typedef struct lisp_x_gc {
5558 repv car;
@@ -750,8 +753,11 @@ x-map-window X-WINDOW [UNRAISED]
750753 rep_DECLARE1 (win, X_WINDOWP);
751754 if (unraised == Qnil)
752755 XMapRaised (dpy, VX_DRAWABLE (win)->id);
753- else
756+ else {
757+ if (debug_windows & DB_WINDOWS_REST)
758+ DB (("%s%s%s: mapping\n", map_request_color, __FUNCTION__, color_reset));
754759 XMapWindow (dpy, VX_DRAWABLE (win)->id);
760+ }
755761 return Qt;
756762 }
757763
@@ -762,6 +768,8 @@ x-unmap-window X-WINDOW
762768 ::end:: */
763769 {
764770 rep_DECLARE1 (win, X_WINDOWP);
771+ if (debug_windows & DB_WINDOWS_REST)
772+ DB (("%s%s%s: UN-mapping\n", unmap_request_color, __FUNCTION__, color_reset));
765773 XUnmapWindow (dpy, VX_DRAWABLE (win)->id);
766774 return Qt;
767775 }
@@ -835,6 +843,9 @@ Destroys the X-DRAWABLE.
835843 if (X_WINDOWP (drawable))
836844 {
837845 deregister_event_handler (VX_DRAWABLE (drawable)->id);
846+ if (debug_windows & DB_WINDOWS_REST)
847+ DB (("%s%s%s: destroying %x\n", unmap_request_color, __FUNCTION__, color_reset,
848+ VX_DRAWABLE (drawable)->id));
838849 XDestroyWindow (dpy, VX_DRAWABLE (drawable)->id);
839850 }
840851 else if (X_PIXMAPP (drawable) || X_BITMAPP (drawable))
@@ -957,8 +968,10 @@ DEFUN ("x-window-back-buffer", Fx_window_back_buffer,
957968 buf = x_back_buffer_from_id (id);
958969 if (buf == 0)
959970 {
971+ DB(("%s XdbeAllocateBackBufferName ...", __FUNCTION__));
960972 buf = XdbeAllocateBackBufferName (dpy, id, XdbeBackground);
961973 XSaveContext (dpy, id, x_dbe_context, (XPointer) buf);
974+ DB(("-> %p\n", buf));
962975 }
963976
964977 if (buf == 0)