changeset 756:cceac4ba259e

Support drawing at root window for X Window
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 26 Aug 2010 14:54:50 +0800
parents 82836f1290b6
children f43224bf3524
files nodejs/testcase.js src/X_supp.c
diffstat 2 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/testcase.js	Thu Aug 26 13:54:53 2010 +0800
+++ b/nodejs/testcase.js	Thu Aug 26 14:54:50 2010 +0800
@@ -1,9 +1,15 @@
 var mbfly = require("mbfly");
 var r = mbfly.Hello(" test");
 var sys = require("sys");
+/* process module is still not supported by nodejs v0.1.97 */
+/* var process = require("process"); */
 sys.puts(r);
 
-var mb_rt = new mbfly.mb_rt(":0.0", 300, 200);
+var display_name = ":0.0";
+/* if(process.argv.length > 2)
+   display_name = process.argv[2]; */
+
+var mb_rt = new mbfly.mb_rt(display_name, 300, 200);
 var root = mb_rt.root;
 sys.puts("root matrix: " +
 	 [root[0], root[1], root[2], root[3], root[4], root[5]]);
--- a/src/X_supp.c	Thu Aug 26 13:54:53 2010 +0800
+++ b/src/X_supp.c	Thu Aug 26 14:54:50 2010 +0800
@@ -428,12 +428,13 @@
 	    handle_x_event(rt);
 	} else {
             for(i=0;i<rt->n_monitor;i++) {
-	        if (rt->monitors[i].type == MONITOR_READ)
+	        if (rt->monitors[i].type == MONITOR_READ) {
 		    if (FD_ISSET(rt->monitors[i].fd, &rfds))
 		    	rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
-	        else if (rt->monitors[i].type == MONITOR_WRITE)
+		} else if (rt->monitors[i].type == MONITOR_WRITE) {
 		    if (FD_ISSET(rt->monitors[i].fd, &wfds))
-		    	rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
+			rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
+		}
             }
 	}
     }
@@ -454,9 +455,27 @@
     XSetWindowAttributes wattr;
     int depth;
     int x, y;
+    int draw_root = 0;
+    const char *disp_name;
+    char disp_buf[32];
+    int cp;
     int r;
 
-    display = XOpenDisplay(display_name);
+    /*
+     * Support drawing on the root window.
+     */
+    disp_name = display_name;
+    if(strstr(display_name, ":root") != NULL) {
+	draw_root = 1;
+	cp = strlen(display_name) - 5;
+	if(cp >= 32)
+	    cp = 31;
+	memcpy(disp_buf, display_name, cp);
+	disp_buf[cp] = 0;
+	disp_name = disp_buf;
+    }
+    
+    display = XOpenDisplay(disp_name);
     if(display == NULL)
 	return ERR;
 
@@ -467,15 +486,19 @@
     wattr.override_redirect = False;
     x = 10;
     y = 10;
-    win = XCreateWindow(display, root,
-			 x, y,
-			 w, h,
-			 1, depth, InputOutput, visual,
-			 CWOverrideRedirect, &wattr);
-    r = XMapWindow(display, win);
-    if(r == -1) {
-	XCloseDisplay(display);
-	return ERR;
+    if(draw_root)
+	win = RootWindowOfScreen(ScreenOfDisplay(display, screen));
+    else {
+	win = XCreateWindow(display, root,
+			    x, y,
+			    w, h,
+			    1, depth, InputOutput, visual,
+			    CWOverrideRedirect, &wattr);
+	r = XMapWindow(display, win);
+	if(r == -1) {
+	    XCloseDisplay(display);
+	    return ERR;
+	}
     }
 
     XSelectInput(display, win, PointerMotionMask | ExposureMask |