• 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

修订版265778cbc80f9e70e287f7deae8d783ef49c899c (tree)
时间2010-12-19 13:28:55
作者Michal Maruska <mmaruska@gmai...>
CommiterMichal Maruska

Log Message

merge of mmc-functions,mmc-debug into mmc-functions-debug

更改概述

差异

--- 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 */
@@ -1446,6 +1458,133 @@ inner_handle_input (repv arg)
14461458 return Qnil;
14471459 }
14481460
1461+
1462+static void
1463+report_event (XEvent *xev)
1464+{
1465+#ifdef USE_XKB
1466+ /* indeed!! */
1467+ if (debug_events)
1468+ report_xkb_event(xev);
1469+#endif
1470+ /* debugging + skipping Release */
1471+ switch (xev->type)
1472+ {
1473+ case KeyRelease:
1474+ case KeyPress:
1475+ {
1476+ char buf[256]; /* static ? */
1477+ u_long code, mods;
1478+
1479+ /* mmc: I prefer to see (the key combination pressed/release) here,
1480+ * se I run the lookup here: */
1481+ if (!translate_event (&code, &mods, &xev))
1482+ break; /* why ??? */
1483+
1484+ lookup_event_name(buf, code, mods);
1485+
1486+
1487+ char* name = "unknown window";
1488+ /* do i need to protect it from GC? */
1489+ Lisp_Window* kw = find_window_by_id(xev->xkey.window);
1490+ if (kw)
1491+ name = (char *) rep_STR (kw->name);
1492+ else if (xev->xkey.window == no_focus_window)
1493+ name = "no_focus_window";
1494+ else if (xev->xkey.window == root_window)
1495+ name = (xev->xkey.subwindow == no_focus_window ) ?
1496+ "no_focus_window via root_window" : "root_window";
1497+
1498+ // xev->xkey.subwindow
1499+ if (debug_keys) /* & DB_EVENTS_TIME */
1500+ DB (("** Key: serial:%s%d%s %s %s time: %u %s%s%s/%d %d\n",
1501+ keys_color ,xev->xkey.serial, color_reset,
1502+ xev->type < LASTEvent ?event_names[xev->type]:"unknown event",
1503+ buf,
1504+ xev->xkey.time, /*my_timestamp(xev->xkey.time),*/
1505+ name,
1506+
1507+ (kw && (kw->id == xev->xkey.window)) ? "window (grab?)" :
1508+ ((kw && (kw->frame == xev->xkey.window)) ? "frame" : ""),
1509+
1510+ (xev->xkey.subwindow == xev->xkey.window) ? "" : "->subwindow"
1511+ ,xev->xkey.window, xev->xkey.subwindow
1512+ /*xev->xkey.time*/
1513+ ));
1514+ if (xev->type==KeyRelease
1515+ && (global_symbol_value (Qeval_key_release_events) == Qnil));
1516+ /* why ?? ... so assert? */
1517+ break;
1518+ }
1519+ default:
1520+ if (! ((xev->type == Expose)
1521+ // || (xev->type == PropertyNotify)
1522+ || (xev->type == VisibilityNotify)
1523+
1524+ /* if i set DB_EVENTS_MISC -> i want to see even those */
1525+ || (!(debug_events & DB_EVENTS_MISC)
1526+ &&
1527+ (((xev->type == UnmapNotify)
1528+ || (xev->type == ConfigureNotify)
1529+ || (xev->type == MapNotify))
1530+ && (xev->xany.window == root_window)))
1531+ /* 64 root_window ... this means, that the event is reported to the root.*/
1532+ ))
1533+ {
1534+ /* do */
1535+ if (debug_events & DB_EVENTS_FLOW)
1536+ {
1537+ /* i'm not interested that the event arrived via root_window !! */
1538+ Window id = xev->xany.window;
1539+ Window event = xev->xany.window;
1540+
1541+ switch (xev->type){
1542+ case UnmapNotify:
1543+ id = xev->xunmap.window;
1544+ break;
1545+ case MapNotify:
1546+ id = xev->xmap.window;
1547+ break;
1548+ case ConfigureNotify:
1549+ id = xev->xconfigure.window;
1550+ break;
1551+ case ConfigureRequest:
1552+ id = xev->xconfigurerequest.window;
1553+ break;
1554+ /* Garbagge collection !!!! am i losing prompt b/c of that? */
1555+ case CreateNotify: /* */
1556+ id = xev->xcreatewindow.window;
1557+ break;
1558+ case DestroyNotify:
1559+ id = xev->xdestroywindow.window;
1560+ /* premature here? */
1561+ break;
1562+ case MapRequest:
1563+ id = xev->xmaprequest.window;
1564+ break;
1565+ default:
1566+ id = xev->xany.window;
1567+ };
1568+ Lisp_Window *w = find_window_by_id (id)? : find_window_by_frame(id);
1569+
1570+ DB (("** Event: serial:%s%d%s: %s%s%s (event: %x win %x: %s)\n",
1571+ event_color, xev->xkey.serial, color_reset,
1572+ event_name_color,
1573+ xev->type < LASTEvent ? event_names[xev->type] : "unknown", color_reset,
1574+ event, id,
1575+ (w) ? rep_STR (w->name) : (u_char *)"unknown"));
1576+ }
1577+ } else {
1578+ /* give a small hint at the quantity.*/
1579+ DB(("%s%s%s", events_color,
1580+ (xev->xany.window == no_focus_window) ? "F":
1581+ (xev->xany.window == root_window) ? "R": "@", color_reset
1582+ )); /* @ */
1583+ }
1584+ };
1585+
1586+}
1587+
14491588 /* Handle all available X events matching event mask MASK. Or any events
14501589 if MASK is zero. */
14511590 void
@@ -1488,15 +1627,7 @@ handle_input_mask(long mask)
14881627 if (xev.type == NoExpose || xev.type == GraphicsExpose)
14891628 continue;
14901629
1491-#ifdef DEBUG
1492- do {
1493- Lisp_Window *w = x_find_window_by_id (xev.xany.window);
1494- DB(("** Event: %s (win %lx: %s)\n",
1495- xev.type < LASTEvent ? event_names[xev.type] : "unknown",
1496- (long)xev.xany.window, w ? (char *) rep_STR (w->name) : "unknown"));
1497- } while (0);
1498-#endif
1499-
1630+ report_event (&xev);
15001631 record_event_time (&xev);
15011632 current_x_event = &xev;
15021633 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
@@ -99,6 +104,10 @@ mapped_not_override_p (Window id)
99104 XWindowAttributes wa;
100105
101106 XGetWindowAttributes(dpy, id, &wa);
107+ if (debug_windows & DB_WINDOWS_REST)
108+ DB (("%s %" FMT_WIN " %s %s\n", __FUNCTION__, id,
109+ (wa.map_state == IsUnmapped)?"is unmapped!":"",
110+ (wa.override_redirect == True)?"has override!":""));
102111 return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
103112 }
104113
@@ -143,7 +152,7 @@ commit_queued_focus_change (void)
143152 {
144153 if (queued_take_focus)
145154 {
146- DB((" sending WM_TAKE_FOCUS %x %ld\n",
155+ DB((" sending WM_TAKE_FOCUS %" FMT_WIN " %ld\n",
147156 (unsigned) queued_focus_id, queued_focus_time));
148157 send_client_message (queued_focus_id,
149158 xa_wm_take_focus,
@@ -151,7 +160,7 @@ commit_queued_focus_change (void)
151160 }
152161 if (queued_set_focus)
153162 {
154- DB((" focusing %x %ld\n",
163+ DB((" focusing %" FMT_WIN " %ld\n",
155164 (unsigned) queued_focus_id, queued_focus_time));
156165 XSetInputFocus (dpy, queued_focus_id,
157166 queued_focus_revert, queued_focus_time);
@@ -231,6 +240,8 @@ get_window_protocols (Lisp_Window *w)
231240 int n;
232241 w->does_wm_take_focus = 0;
233242 w->does_wm_delete_window = 0;
243+ if (debug_windows & DB_WINDOWS_REST)
244+ DB (("W: %s: %s\n",__FUNCTION__,rep_STR(w->name)));
234245 if (XGetWMProtocols (dpy, w->id, &prot, &n) != 0)
235246 {
236247 int i;
@@ -239,12 +250,14 @@ get_window_protocols (Lisp_Window *w)
239250 if (prot[i] == xa_wm_take_focus)
240251 {
241252 w->does_wm_take_focus = 1;
242- DB((" WM_TAKE_FOCUS is set\n"));
253+ if (debug_windows & DB_WINDOWS_PROT)
254+ DB (("W: WM_TAKE_FOCUS is set\n"));
243255 }
244256 if (prot[i] == xa_wm_delete_window)
245257 {
246258 w->does_wm_delete_window = 1;
247- DB((" WM_DELETE_WINDOW is set\n"));
259+ if (debug_windows & DB_WINDOWS_PROT)
260+ DB (("W: WM_DELETE_WINDOW is set\n"));
248261 }
249262 }
250263 XFree (prot);
@@ -279,8 +292,12 @@ find_window_by_id (Window id)
279292 {
280293 Lisp_Window *w;
281294 w = window_list;
295+ if (debug_windows & DB_WINDOWS_FIND)
296+ DB(("%s searching for %" FMT_WIN "\n", __FUNCTION__, id));
282297 while (w != 0 && w->id != id && w->frame != id)
283298 w = w->next;
299+ if (debug_windows & DB_WINDOWS_FIND)
300+ DB(("%s %sfound\n", __FUNCTION__, (w)?"":"not "));
284301 if (w != 0 && WINDOW_IS_GONE_P (w))
285302 w = 0;
286303 return w;
@@ -301,7 +318,8 @@ x_find_window_by_id (Window id)
301318 void
302319 install_window_frame (Lisp_Window *w)
303320 {
304- DB(("install_window_frame (%s)\n", rep_STR(w->name)));
321+ if ((debug_windows & DB_WINDOWS_FRAME) || debug_frames)
322+ DB (("%s%s%s on %s\n", reparent_color,__FUNCTION__, color_reset, rep_STR(w->name)));
305323 if (!w->reparented && w->frame != 0 && !WINDOW_IS_GONE_P (w))
306324 {
307325 XSetWindowAttributes wa;
@@ -309,6 +327,9 @@ install_window_frame (Lisp_Window *w)
309327 XSelectInput (dpy, w->frame, FRAME_EVENTS);
310328
311329 before_local_map (w);
330+ if (debug_windows & DB_WINDOWS_FRAME)
331+ DB(("%sXReparentWindow: %" FMT_WIN " %s -> %" FMT_WIN "%s\n", reparent_color,
332+ w->id, rep_STR(w->name), w->frame, color_reset));
312333 XReparentWindow (dpy, w->id, w->frame, -w->frame_x, -w->frame_y);
313334 w->reparented = TRUE;
314335 after_local_map (w);
@@ -324,16 +345,18 @@ install_window_frame (Lisp_Window *w)
324345 wa.win_gravity = StaticGravity;
325346 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
326347
327- DB((" reparented to %lx [%dx%d%+d%+d]\n",
328- w->frame, w->frame_width, w->frame_height,
329- w->frame_x, w->frame_y));
348+ if (debug_windows & DB_WINDOWS_FRAME)
349+ DB((" reparented to %" FMT_WIN " [%dx%d%+d%+d]\n",
350+ w->frame, w->frame_width, w->frame_height,
351+ w->frame_x, w->frame_y));
330352 }
331353 }
332354
333355 void
334356 remove_window_frame (Lisp_Window *w)
335357 {
336- DB(("remove_window_frame (%s)\n", rep_STR(w->name)));
358+ if (debug_windows & DB_WINDOWS_FRAME)
359+ DB (("%s%s%s %s\n", reparent_color, __FUNCTION__, color_reset, rep_STR(w->name)));
337360 if (w->reparented && !WINDOW_IS_GONE_P (w))
338361 {
339362 XSetWindowAttributes wa;
@@ -343,6 +366,8 @@ remove_window_frame (Lisp_Window *w)
343366 wa.win_gravity = w->attr.win_gravity;
344367 XChangeWindowAttributes (dpy, w->id, CWWinGravity, &wa);
345368
369+ DB(("%sXReparentWindow: %" FMT_WIN " %s%s -> root_window at %s%d,%d%s\n", reparent_color,
370+ w->id, rep_STR(w->name), color_reset, reparent_color, w->attr.x, w->attr.y, color_reset));
346371 before_local_map (w);
347372 XReparentWindow (dpy, w->id, root_window, w->attr.x, w->attr.y);
348373 w->reparented = FALSE;
@@ -354,6 +379,9 @@ remove_window_frame (Lisp_Window *w)
354379
355380 if (!w->mapped)
356381 XRemoveFromSaveSet (dpy, w->id);
382+ } else {
383+ if (debug_windows & DB_WINDOWS_FRAME)
384+ DB (("%s: window is gone, or reparented outside, doing nothing\n", __FUNCTION__));
357385 }
358386 }
359387
@@ -430,6 +458,13 @@ Lisp_Window *
430458 add_window (Window id)
431459 {
432460 Lisp_Window *w = rep_ALLOC_CELL(sizeof (Lisp_Window));
461+
462+ if (debug_windows & DB_WINDOWS_ADD) {
463+ if (id == root_window)
464+ DB (("W: add_window (ROOT)\n"));
465+ else
466+ DB (("W: add_window (%" FMT_WIN ")\n", id));
467+ };
433468 if (w != 0)
434469 {
435470 rep_GC_root gc_win;
@@ -438,11 +473,6 @@ add_window (Window id)
438473 unsigned int xwcm;
439474 long supplied;
440475
441- DB(("add_window (%lx)\n", id));
442-
443- if (id == root_window)
444- DB((" ** adding root window!?\n"));
445-
446476 rep_data_after_gc += sizeof (Lisp_Window);
447477 memset (w, 0, sizeof (Lisp_Window));
448478
@@ -499,9 +529,10 @@ add_window (Window id)
499529 w->shaped = bounding ? 1 : 0;
500530 }
501531
502- DB((" name=`%s' x=%d y=%d width=%d height=%d\n",
503- rep_STR(w->name), w->attr.x, w->attr.y,
504- w->attr.width, w->attr.height));
532+ if (debug_windows & DB_WINDOWS_ADD)
533+ DB (("W: name=`%s' x=%d y=%d width=%d height=%d\n",
534+ rep_STR(w->name), w->attr.x, w->attr.y,
535+ w->attr.width, w->attr.height));
505536
506537 xwcm = CWX | CWX | CWWidth | CWHeight | CWBorderWidth;
507538 xwc.x = w->attr.x;
@@ -743,6 +774,11 @@ Note that these are Lisp properties not X properties.
743774 {
744775 repv plist;
745776 rep_DECLARE1(win, XWINDOWP);
777+ if (debug_windows & DB_WINDOWS_PUT){
778+ DB(("%s %s prop: %s\n", __FUNCTION__, rep_STR(VWIN(win)->name),
779+ rep_SYMBOLP(prop)? (char*)rep_STR(rep_SYM(prop)->name):"not a symbol"));
780+ /* Fbacktrace(Fstderr_file()); //Fbacktrace(Qnil);*/
781+ }
746782 plist = VWIN(win)->plist;
747783 while (rep_CONSP(plist) && rep_CONSP(rep_CDR(plist)))
748784 {
@@ -891,6 +927,12 @@ new frame constructed as specified by FRAME.
891927 {
892928 rep_DECLARE1(win, WINDOWP);
893929 rep_DECLARE2(frame, rep_LISTP);
930+
931+ if (debug_frames && debug_windows) {
932+ DB(("%s:%s\n", __FUNCTION__, rep_STR(VWIN(win)->name)));
933+ Fbacktrace(Fstderr_file());
934+ }
935+
894936 Fgrab_server ();
895937
896938 if (VWIN(win)->reparented)
@@ -916,6 +958,11 @@ Reinitialises and recalibrates the window frame of WINDOW.
916958 rep_DECLARE1(win, WINDOWP);
917959 if (VWIN(win)->frame != 0 && VWIN(win)->rebuild_frame != 0)
918960 {
961+ if (debug_frames || (debug_windows & DB_WINDOWS_FRAME))
962+ DB(("%s: %s->rebuild_frame %d %d\n", __FUNCTION__,
963+ rep_STR(VWIN(win)->name),
964+ VWIN(win)->attr.width,VWIN(win)->attr.height));
965+
919966 VWIN(win)->rebuild_frame (VWIN(win));
920967 refresh_frame_parts (VWIN(win));
921968 Fcall_window_hook (Qafter_framing_hook, win, Qnil, Qnil);
@@ -1380,6 +1427,8 @@ description of HOOK-TYPE.
13801427 tem = Fwindow_get (win, hook, Qnil);
13811428 if (tem && tem != Qnil)
13821429 {
1430+ if (debug_windows & DB_WINDOWS_HOOKS)
1431+ DB (("W: call-window-hook: private %s\n", window_name (VWIN(win))));
13831432 tem = Fcall_hook (tem, args, type);
13841433 if (!tem || (type == Qand && tem == Qnil)
13851434 || (type == Qor && tem != Qnil))
@@ -1387,7 +1436,11 @@ description of HOOK-TYPE.
13871436 goto out;
13881437 }
13891438 }
1439+ if (debug_windows & DB_WINDOWS_HOOKS)
1440+ DB (("W: call-window-hook: public %s\n", window_name (VWIN(win))));
13901441 tem = Fcall_hook (hook, args, type);
1442+ if (debug_windows & DB_WINDOWS_HOOKS)
1443+ DB (("W: call-window-hook: end %s\n", window_name (VWIN(win))));
13911444 out:
13921445 rep_POPGC; rep_POPGC; rep_POPGC;
13931446 return tem;
@@ -1540,16 +1593,22 @@ static void
15401593 window_prin (repv stream, repv win)
15411594 {
15421595 char buf[128];
1543- sprintf (buf, "#<window %lx>", VWIN(win)->id);
1596+ snprintf (buf, sizeof(buf), "#<window %" FMT_WIN " %s>", VWIN(win)->id, rep_STR(VWIN(win)->name));
15441597 rep_stream_puts (stream, buf, -1, FALSE);
15451598 }
15461599
15471600 static void
15481601 window_mark (repv win)
15491602 {
1603+ if (debug_windows & DB_WINDOWS_GC)
1604+ DB(("%s: %p %s\n", __FUNCTION__, (void*) win, rep_STR(VWIN(win)->name)));
15501605 rep_MARKVAL(VWIN(win)->plist);
15511606 rep_MARKVAL(VWIN(win)->frame_style);
1607+ if (debug_windows & DB_WINDOWS_GC)
1608+ DB(("%s: now frame parts\n", __FUNCTION__));
15521609 mark_frame_parts (VWIN(win));
1610+ if (debug_windows & DB_WINDOWS_GC)
1611+ DB(("%s: now strings\n", __FUNCTION__));
15531612 rep_MARKVAL(VWIN(win)->name);
15541613 rep_MARKVAL(VWIN(win)->full_name);
15551614 rep_MARKVAL(VWIN(win)->icon_name);
@@ -1567,6 +1626,10 @@ window_mark_type (void)
15671626 {
15681627 if (!WINDOW_IS_GONE_P (w) || !w->destroyed)
15691628 rep_MARKVAL(rep_VAL(w));
1629+ else
1630+ if (debug_windows & DB_WINDOWS_GC)
1631+ DB(("%s: %snot marking%s %p %s\n", __FUNCTION__, warning_color, color_reset,
1632+ w, rep_STR(w->name)));
15701633 }
15711634 for (ph = prop_handlers; ph != 0; ph = ph->next)
15721635 rep_MARKVAL (ph->prop);
@@ -1577,12 +1640,17 @@ static void
15771640 window_sweep (void)
15781641 {
15791642 Lisp_Window **ptr = &window_list;
1643+
1644+ if (debug_windows & DB_WINDOWS_GC)
1645+ DB(("%s\n", __FUNCTION__));
15801646 while (*ptr != 0)
15811647 {
15821648 Lisp_Window *w = *ptr;
15831649 if (!rep_GC_CELL_MARKEDP(rep_VAL(w)))
15841650 {
15851651 assert (!window_in_stacking_list_p (w));
1652+ if (debug_windows & DB_WINDOWS_GC)
1653+ DB(("%s another window gone pointer: %p\n", __FUNCTION__, w));
15861654 destroy_window_frame (w, FALSE);
15871655 if (w->wmhints != 0)
15881656 XFree (w->wmhints);
@@ -1597,6 +1665,8 @@ window_sweep (void)
15971665 rep_GC_CLR_CELL(rep_VAL(w));
15981666 }
15991667 }
1668+ if (debug_windows & DB_WINDOWS_GC)
1669+ DB(("%s END\n", __FUNCTION__));
16001670 }
16011671
16021672 /* initialisation */
@@ -1608,6 +1678,8 @@ manage_windows (void)
16081678 unsigned int nchildren, i;
16091679 int revert_to;
16101680
1681+ if (debug_windows & DB_WINDOWS_REST)
1682+ DB(("%s\n", __FUNCTION__));
16111683 Fgrab_server ();
16121684
16131685 XGetInputFocus (dpy, &focus, &revert_to);
@@ -1627,8 +1699,13 @@ manage_windows (void)
16271699 }
16281700 focus = child;
16291701 }
1702+ else if (debug_windows & DB_WINDOWS_REST)
1703+ DB(("%s: (focus != PointerRoot)\n", __FUNCTION__));
16301704
16311705 XQueryTree (dpy, root_window, &root, &parent, &children, &nchildren);
1706+ if (debug_windows & DB_WINDOWS_REST)
1707+ DB(("%s: XQueryTree returned %d children\n",__FUNCTION__, nchildren));
1708+
16321709 initialising = TRUE;
16331710 for (i = 0; i < nchildren; i++)
16341711 {
--- 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)