• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

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

修订版90f566e71e4aa50c346408f282799a78ee367841 (tree)
时间2010-12-19 13:32:10
作者Michal Maruska <mmaruska@gmai...>
CommiterMichal Maruska

Log Message

merge of new-mmc-delete-windows,mmc-debug into mmc-delete-windows-debug

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

更改概述

差异

--- 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 */
@@ -1430,6 +1442,133 @@ inner_handle_input (repv arg)
14301442 return Qnil;
14311443 }
14321444
1445+
1446+static void
1447+report_event (XEvent *xev)
1448+{
1449+#ifdef USE_XKB
1450+ /* indeed!! */
1451+ if (debug_events)
1452+ report_xkb_event(xev);
1453+#endif
1454+ /* debugging + skipping Release */
1455+ switch (xev->type)
1456+ {
1457+ case KeyRelease:
1458+ case KeyPress:
1459+ {
1460+ char buf[256]; /* static ? */
1461+ u_long code, mods;
1462+
1463+ /* mmc: I prefer to see (the key combination pressed/release) here,
1464+ * se I run the lookup here: */
1465+ if (!translate_event (&code, &mods, &xev))
1466+ break; /* why ??? */
1467+
1468+ lookup_event_name(buf, code, mods);
1469+
1470+
1471+ char* name = "unknown window";
1472+ /* do i need to protect it from GC? */
1473+ Lisp_Window* kw = find_window_by_id(xev->xkey.window);
1474+ if (kw)
1475+ name = (char *) rep_STR (kw->name);
1476+ else if (xev->xkey.window == no_focus_window)
1477+ name = "no_focus_window";
1478+ else if (xev->xkey.window == root_window)
1479+ name = (xev->xkey.subwindow == no_focus_window ) ?
1480+ "no_focus_window via root_window" : "root_window";
1481+
1482+ // xev->xkey.subwindow
1483+ if (debug_keys) /* & DB_EVENTS_TIME */
1484+ DB (("** Key: serial:%s%d%s %s %s time: %u %s%s%s/%d %d\n",
1485+ keys_color ,xev->xkey.serial, color_reset,
1486+ xev->type < LASTEvent ?event_names[xev->type]:"unknown event",
1487+ buf,
1488+ xev->xkey.time, /*my_timestamp(xev->xkey.time),*/
1489+ name,
1490+
1491+ (kw && (kw->id == xev->xkey.window)) ? "window (grab?)" :
1492+ ((kw && (kw->frame == xev->xkey.window)) ? "frame" : ""),
1493+
1494+ (xev->xkey.subwindow == xev->xkey.window) ? "" : "->subwindow"
1495+ ,xev->xkey.window, xev->xkey.subwindow
1496+ /*xev->xkey.time*/
1497+ ));
1498+ if (xev->type==KeyRelease
1499+ && (global_symbol_value (Qeval_key_release_events) == Qnil));
1500+ /* why ?? ... so assert? */
1501+ break;
1502+ }
1503+ default:
1504+ if (! ((xev->type == Expose)
1505+ // || (xev->type == PropertyNotify)
1506+ || (xev->type == VisibilityNotify)
1507+
1508+ /* if i set DB_EVENTS_MISC -> i want to see even those */
1509+ || (!(debug_events & DB_EVENTS_MISC)
1510+ &&
1511+ (((xev->type == UnmapNotify)
1512+ || (xev->type == ConfigureNotify)
1513+ || (xev->type == MapNotify))
1514+ && (xev->xany.window == root_window)))
1515+ /* 64 root_window ... this means, that the event is reported to the root.*/
1516+ ))
1517+ {
1518+ /* do */
1519+ if (debug_events & DB_EVENTS_FLOW)
1520+ {
1521+ /* i'm not interested that the event arrived via root_window !! */
1522+ Window id = xev->xany.window;
1523+ Window event = xev->xany.window;
1524+
1525+ switch (xev->type){
1526+ case UnmapNotify:
1527+ id = xev->xunmap.window;
1528+ break;
1529+ case MapNotify:
1530+ id = xev->xmap.window;
1531+ break;
1532+ case ConfigureNotify:
1533+ id = xev->xconfigure.window;
1534+ break;
1535+ case ConfigureRequest:
1536+ id = xev->xconfigurerequest.window;
1537+ break;
1538+ /* Garbagge collection !!!! am i losing prompt b/c of that? */
1539+ case CreateNotify: /* */
1540+ id = xev->xcreatewindow.window;
1541+ break;
1542+ case DestroyNotify:
1543+ id = xev->xdestroywindow.window;
1544+ /* premature here? */
1545+ break;
1546+ case MapRequest:
1547+ id = xev->xmaprequest.window;
1548+ break;
1549+ default:
1550+ id = xev->xany.window;
1551+ };
1552+ Lisp_Window *w = find_window_by_id (id)? : find_window_by_frame(id);
1553+
1554+ DB (("** Event: serial:%s%d%s: %s%s%s (event: %x win %x: %s)\n",
1555+ event_color, xev->xkey.serial, color_reset,
1556+ event_name_color,
1557+ xev->type < LASTEvent ? event_names[xev->type] : "unknown", color_reset,
1558+ event, id,
1559+ (w) ? rep_STR (w->name) : (u_char *)"unknown"));
1560+ }
1561+ } else {
1562+ /* give a small hint at the quantity.*/
1563+ DB(("%s%s%s", events_color,
1564+ (xev->xany.window == no_focus_window) ? "F":
1565+ (xev->xany.window == root_window) ? "R": "@", color_reset
1566+ )); /* @ */
1567+ }
1568+ };
1569+
1570+}
1571+
14331572 /* Handle all available X events matching event mask MASK. Or any events
14341573 if MASK is zero. */
14351574 void
@@ -1468,15 +1607,7 @@ handle_input_mask(long mask)
14681607 if (xev.type == NoExpose || xev.type == GraphicsExpose)
14691608 continue;
14701609
1471-#ifdef DEBUG
1472- do {
1473- Lisp_Window *w = find_window_by_id (xev.xany.window);
1474- DB(("** Event: %s (win %lx: %s)\n",
1475- xev.type < LASTEvent ? event_names[xev.type] : "unknown",
1476- (long)xev.xany.window, w ? (char *) rep_STR (w->name) : "unknown"));
1477- } while (0);
1478-#endif
1479-
1610+ report_event (&xev);
14801611 record_event_time (&xev);
14811612 current_x_event = &xev;
14821613 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
@@ -500,6 +500,7 @@ where OPTIONS are any of:\n\
500500 Fset (Qfonts_are_fontsets, Qnil);
501501 }
502502
503+ set_init ();
503504 /* call all init funcs... */
504505 session_init ();
505506 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
@@ -97,6 +102,10 @@ mapped_not_override_p (Window id)
97102 XWindowAttributes wa;
98103
99104 XGetWindowAttributes(dpy, id, &wa);
105+ if (debug_windows & DB_WINDOWS_REST)
106+ DB (("%s %" FMT_WIN " %s %s\n", __FUNCTION__, id,
107+ (wa.map_state == IsUnmapped)?"is unmapped!":"",
108+ (wa.override_redirect == True)?"has override!":""));
100109 return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
101110 }
102111
@@ -141,7 +150,7 @@ commit_queued_focus_change (void)
141150 {
142151 if (queued_take_focus)
143152 {
144- DB((" sending WM_TAKE_FOCUS %x %ld\n",
153+ DB((" sending WM_TAKE_FOCUS %" FMT_WIN " %ld\n",
145154 (unsigned) queued_focus_id, queued_focus_time));
146155 send_client_message (queued_focus_id,
147156 xa_wm_take_focus,
@@ -149,7 +158,7 @@ commit_queued_focus_change (void)
149158 }
150159 if (queued_set_focus)
151160 {
152- DB((" focusing %x %ld\n",
161+ DB((" focusing %" FMT_WIN " %ld\n",
153162 (unsigned) queued_focus_id, queued_focus_time));
154163 XSetInputFocus (dpy, queued_focus_id,
155164 queued_focus_revert, queued_focus_time);
@@ -229,6 +238,8 @@ get_window_protocols (Lisp_Window *w)
229238 int n;
230239 w->does_wm_take_focus = 0;
231240 w->does_wm_delete_window = 0;
241+ if (debug_windows & DB_WINDOWS_REST)
242+ DB (("W: %s: %s\n",__FUNCTION__,rep_STR(w->name)));
232243 if (XGetWMProtocols (dpy, w->id, &prot, &n) != 0)
233244 {
234245 int i;
@@ -237,12 +248,14 @@ get_window_protocols (Lisp_Window *w)
237248 if (prot[i] == xa_wm_take_focus)
238249 {
239250 w->does_wm_take_focus = 1;
240- DB((" WM_TAKE_FOCUS is set\n"));
251+ if (debug_windows & DB_WINDOWS_PROT)
252+ DB (("W: WM_TAKE_FOCUS is set\n"));
241253 }
242254 if (prot[i] == xa_wm_delete_window)
243255 {
244256 w->does_wm_delete_window = 1;
245- DB((" WM_DELETE_WINDOW is set\n"));
257+ if (debug_windows & DB_WINDOWS_PROT)
258+ DB (("W: WM_DELETE_WINDOW is set\n"));
246259 }
247260 }
248261 XFree (prot);
@@ -277,6 +290,8 @@ find_window_by_id (Window id)
277290 {
278291 Lisp_Window *w;
279292 w = window_list;
293+ if (debug_windows & DB_WINDOWS_FIND)
294+ DB(("%s searching for %" FMT_WIN "\n", __FUNCTION__, id));
280295 while (w != 0 && w->id != id && w->frame != id)
281296 w = w->next;
282297 return w;
@@ -285,7 +300,8 @@ find_window_by_id (Window id)
285300 void
286301 install_window_frame (Lisp_Window *w)
287302 {
288- DB(("install_window_frame (%s)\n", rep_STR(w->name)));
303+ if ((debug_windows & DB_WINDOWS_FRAME) || debug_frames)
304+ DB (("%s%s%s on %s\n", reparent_color,__FUNCTION__, color_reset, rep_STR(w->name)));
289305 if (!w->reparented && w->frame != 0 && !WINDOW_IS_GONE_P (w))
290306 {
291307 XSetWindowAttributes wa;
@@ -293,6 +309,9 @@ install_window_frame (Lisp_Window *w)
293309 XSelectInput (dpy, w->frame, FRAME_EVENTS);
294310
295311 before_local_map (w);
312+ if (debug_windows & DB_WINDOWS_FRAME)
313+ DB(("%sXReparentWindow: %" FMT_WIN " %s -> %" FMT_WIN "%s\n", reparent_color,
314+ w->id, rep_STR(w->name), w->frame, color_reset));
296315 XReparentWindow (dpy, w->id, w->frame, -w->frame_x, -w->frame_y);
297316 w->reparented = TRUE;
298317 after_local_map (w);
@@ -308,16 +327,18 @@ install_window_frame (Lisp_Window *w)
308327 wa.win_gravity = StaticGravity;
309328 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
310329
311- DB((" reparented to %lx [%dx%d%+d%+d]\n",
312- w->frame, w->frame_width, w->frame_height,
313- w->frame_x, w->frame_y));
330+ if (debug_windows & DB_WINDOWS_FRAME)
331+ DB((" reparented to %" FMT_WIN " [%dx%d%+d%+d]\n",
332+ w->frame, w->frame_width, w->frame_height,
333+ w->frame_x, w->frame_y));
314334 }
315335 }
316336
317337 void
318338 remove_window_frame (Lisp_Window *w, bool restack)
319339 {
320- DB(("remove_window_frame (%s)\n", rep_STR(w->name)));
340+ if (debug_windows & DB_WINDOWS_FRAME)
341+ DB (("%s%s%s %s\n", reparent_color, __FUNCTION__, color_reset, rep_STR(w->name)));
321342 if (w->reparented && !WINDOW_IS_GONE_P (w))
322343 {
323344 XSetWindowAttributes wa;
@@ -327,6 +348,8 @@ remove_window_frame (Lisp_Window *w, bool restack)
327348 wa.win_gravity = w->attr.win_gravity;
328349 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
329350
351+ DB(("%sXReparentWindow: %" FMT_WIN " %s%s -> root_window at %s%d,%d%s\n", reparent_color,
352+ w->id, rep_STR(w->name), color_reset, reparent_color, w->attr.x, w->attr.y, color_reset));
330353 before_local_map (w);
331354 XReparentWindow (dpy, w->id, root_window, w->attr.x, w->attr.y);
332355 w->reparented = FALSE;
@@ -339,6 +362,9 @@ remove_window_frame (Lisp_Window *w, bool restack)
339362
340363 if (!w->mapped)
341364 XRemoveFromSaveSet (dpy, w->id);
365+ } else {
366+ if (debug_windows & DB_WINDOWS_FRAME)
367+ DB (("%s: window is gone, or reparented outside, doing nothing\n", __FUNCTION__));
342368 }
343369 }
344370
@@ -415,6 +441,13 @@ Lisp_Window *
415441 add_window (Window id)
416442 {
417443 Lisp_Window *w = rep_ALLOC_CELL(sizeof (Lisp_Window));
444+
445+ if (debug_windows & DB_WINDOWS_ADD) {
446+ if (id == root_window)
447+ DB (("W: add_window (ROOT)\n"));
448+ else
449+ DB (("W: add_window (%" FMT_WIN ")\n", id));
450+ };
418451 if (w != 0)
419452 {
420453 rep_GC_root gc_win;
@@ -423,11 +456,6 @@ add_window (Window id)
423456 unsigned int xwcm;
424457 long supplied;
425458
426- DB(("add_window (%lx)\n", id));
427-
428- if (id == root_window)
429- DB((" ** adding root window!?\n"));
430-
431459 rep_data_after_gc += sizeof (Lisp_Window);
432460 memset (w, 0, sizeof (Lisp_Window));
433461
@@ -484,9 +512,10 @@ add_window (Window id)
484512 w->shaped = bounding ? 1 : 0;
485513 }
486514
487- DB((" name=`%s' x=%d y=%d width=%d height=%d\n",
488- rep_STR(w->name), w->attr.x, w->attr.y,
489- w->attr.width, w->attr.height));
515+ if (debug_windows & DB_WINDOWS_ADD)
516+ DB (("W: name=`%s' x=%d y=%d width=%d height=%d\n",
517+ rep_STR(w->name), w->attr.x, w->attr.y,
518+ w->attr.width, w->attr.height));
490519
491520 xwcm = CWX | CWX | CWWidth | CWHeight | CWBorderWidth;
492521 xwc.x = w->attr.x;
@@ -718,6 +747,11 @@ Note that these are Lisp properties not X properties.
718747 {
719748 repv plist;
720749 rep_DECLARE1(win, XWINDOWP);
750+ if (debug_windows & DB_WINDOWS_PUT){
751+ DB(("%s %s prop: %s\n", __FUNCTION__, rep_STR(VWIN(win)->name),
752+ rep_SYMBOLP(prop)? (char*)rep_STR(rep_SYM(prop)->name):"not a symbol"));
753+ /* Fbacktrace(Fstderr_file()); //Fbacktrace(Qnil);*/
754+ }
721755 plist = VWIN(win)->plist;
722756 while (rep_CONSP(plist) && rep_CONSP(rep_CDR(plist)))
723757 {
@@ -866,6 +900,12 @@ new frame constructed as specified by FRAME.
866900 {
867901 rep_DECLARE1(win, WINDOWP);
868902 rep_DECLARE2(frame, rep_LISTP);
903+
904+ if (debug_frames && debug_windows) {
905+ DB(("%s:%s\n", __FUNCTION__, rep_STR(VWIN(win)->name)));
906+ Fbacktrace(Fstderr_file());
907+ }
908+
869909 Fgrab_server ();
870910
871911 if (VWIN(win)->reparented)
@@ -891,6 +931,11 @@ Reinitialises and recalibrates the window frame of WINDOW.
891931 rep_DECLARE1(win, WINDOWP);
892932 if (VWIN(win)->frame != 0 && VWIN(win)->rebuild_frame != 0)
893933 {
934+ if (debug_frames || (debug_windows & DB_WINDOWS_FRAME))
935+ DB(("%s: %s->rebuild_frame %d %d\n", __FUNCTION__,
936+ rep_STR(VWIN(win)->name),
937+ VWIN(win)->attr.width,VWIN(win)->attr.height));
938+
894939 VWIN(win)->rebuild_frame (VWIN(win));
895940 refresh_frame_parts (VWIN(win));
896941 Fcall_window_hook (Qafter_framing_hook, win, Qnil, Qnil);
@@ -1355,6 +1400,8 @@ description of HOOK-TYPE.
13551400 tem = Fwindow_get (win, hook, Qnil);
13561401 if (tem && tem != Qnil)
13571402 {
1403+ if (debug_windows & DB_WINDOWS_HOOKS)
1404+ DB (("W: call-window-hook: private %s\n", window_name (VWIN(win))));
13581405 tem = Fcall_hook (tem, args, type);
13591406 if (!tem || (type == Qand && tem == Qnil)
13601407 || (type == Qor && tem != Qnil))
@@ -1362,7 +1409,11 @@ description of HOOK-TYPE.
13621409 goto out;
13631410 }
13641411 }
1412+ if (debug_windows & DB_WINDOWS_HOOKS)
1413+ DB (("W: call-window-hook: public %s\n", window_name (VWIN(win))));
13651414 tem = Fcall_hook (hook, args, type);
1415+ if (debug_windows & DB_WINDOWS_HOOKS)
1416+ DB (("W: call-window-hook: end %s\n", window_name (VWIN(win))));
13661417 out:
13671418 rep_POPGC; rep_POPGC; rep_POPGC;
13681419 return tem;
@@ -1515,16 +1566,22 @@ static void
15151566 window_prin (repv stream, repv win)
15161567 {
15171568 char buf[128];
1518- sprintf (buf, "#<window %lx>", VWIN(win)->id);
1569+ snprintf (buf, sizeof(buf), "#<window %" FMT_WIN " %s>", VWIN(win)->id, rep_STR(VWIN(win)->name));
15191570 rep_stream_puts (stream, buf, -1, FALSE);
15201571 }
15211572
15221573 static void
15231574 window_mark (repv win)
15241575 {
1576+ if (debug_windows & DB_WINDOWS_GC)
1577+ DB(("%s: %p %s\n", __FUNCTION__, (void*) win, rep_STR(VWIN(win)->name)));
15251578 rep_MARKVAL(VWIN(win)->plist);
15261579 rep_MARKVAL(VWIN(win)->frame_style);
1580+ if (debug_windows & DB_WINDOWS_GC)
1581+ DB(("%s: now frame parts\n", __FUNCTION__));
15271582 mark_frame_parts (VWIN(win));
1583+ if (debug_windows & DB_WINDOWS_GC)
1584+ DB(("%s: now strings\n", __FUNCTION__));
15281585 rep_MARKVAL(VWIN(win)->name);
15291586 rep_MARKVAL(VWIN(win)->full_name);
15301587 rep_MARKVAL(VWIN(win)->icon_name);
@@ -1543,6 +1600,10 @@ window_mark_type (void)
15431600 // !(a || b) || ! b = ! (a || b && b)
15441601 if (! (w->destroyed && (w->id == 0))) // (!WINDOW_IS_GONE_P (w) || !w->destroyed)
15451602 rep_MARKVAL(rep_VAL(w));
1603+ else
1604+ if (debug_windows & DB_WINDOWS_GC)
1605+ DB(("%s: %snot marking%s %p %s\n", __FUNCTION__, warning_color, color_reset,
1606+ w, rep_STR(w->name)));
15461607 }
15471608 for (ph = prop_handlers; ph != 0; ph = ph->next)
15481609 rep_MARKVAL (ph->prop);
@@ -1553,12 +1614,17 @@ static void
15531614 window_sweep (void)
15541615 {
15551616 Lisp_Window **ptr = &window_list;
1617+
1618+ if (debug_windows & DB_WINDOWS_GC)
1619+ DB(("%s\n", __FUNCTION__));
15561620 while (*ptr != 0)
15571621 {
15581622 Lisp_Window *w = *ptr;
15591623 if (!rep_GC_CELL_MARKEDP(rep_VAL(w)))
15601624 {
15611625 assert (!window_in_stacking_list_p (w));
1626+ if (debug_windows & DB_WINDOWS_GC)
1627+ DB(("%s another window gone pointer: %p\n", __FUNCTION__, w));
15621628 destroy_window_frame (w, FALSE);
15631629 if (w->wmhints != 0)
15641630 XFree (w->wmhints);
@@ -1573,6 +1639,8 @@ window_sweep (void)
15731639 rep_GC_CLR_CELL(rep_VAL(w));
15741640 }
15751641 }
1642+ if (debug_windows & DB_WINDOWS_GC)
1643+ DB(("%s END\n", __FUNCTION__));
15761644 }
15771645
15781646 /* initialisation */
@@ -1584,6 +1652,8 @@ manage_windows (void)
15841652 unsigned int nchildren, i;
15851653 int revert_to;
15861654
1655+ if (debug_windows & DB_WINDOWS_REST)
1656+ DB(("%s\n", __FUNCTION__));
15871657 Fgrab_server ();
15881658
15891659 XGetInputFocus (dpy, &focus, &revert_to);
@@ -1603,8 +1673,13 @@ manage_windows (void)
16031673 }
16041674 focus = child;
16051675 }
1676+ else if (debug_windows & DB_WINDOWS_REST)
1677+ DB(("%s: (focus != PointerRoot)\n", __FUNCTION__));
16061678
16071679 XQueryTree (dpy, root_window, &root, &parent, &children, &nchildren);
1680+ if (debug_windows & DB_WINDOWS_REST)
1681+ DB(("%s: XQueryTree returned %d children\n",__FUNCTION__, nchildren));
1682+
16081683 initialising = TRUE;
16091684 for (i = 0; i < nchildren; i++)
16101685 {
--- 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)