Created
January 18, 2011 04:58
-
-
Save iratqq/784007 to your computer and use it in GitHub Desktop.
dock support for dzen2-0.8.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- main.c.orig Tue Jan 18 13:33:17 2011 | |
+++ main.c Tue Jan 18 13:51:22 2011 | |
@@ -19,6 +19,7 @@ | |
#include <sys/select.h> | |
#include <sys/time.h> | |
#include <sys/types.h> | |
+#include <sys/param.h> | |
Dzen dzen = {0}; | |
static int last_cnt = 0; | |
@@ -275,36 +276,153 @@ | |
} | |
#endif | |
-static void | |
-set_net_wm_strut_partial_for(Display *dpy, Window w) { | |
- unsigned long strut[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |
+static void | |
+set_docking_ewmh_info(Display *dpy, Window w, int dock) { | |
+ unsigned long strut[12] = { 0 }; | |
+ unsigned long strut_s[4] = { 0 }; | |
XWindowAttributes wa; | |
+ Atom type; | |
+ unsigned int desktop; | |
+ pid_t cur_pid; | |
+ char *host_name; | |
+ XTextProperty txt_prop; | |
+ XRectangle si; | |
+#ifdef DZEN_XINERAMA | |
+ XineramaScreenInfo *xsi; | |
+ int screen_count,i,max_height; | |
+#endif | |
- XGetWindowAttributes(dpy, w, &wa); | |
+ host_name = emalloc(MAXHOSTNAMELEN); | |
+ if( (gethostname(host_name, MAXHOSTNAMELEN) > -1) && | |
+ (cur_pid = getpid()) ) { | |
- if(wa.y == 0) { | |
- strut[2] = wa.height; | |
+ XStringListToTextProperty(&host_name, 1, &txt_prop); | |
+ XSetWMClientMachine(dpy, w, &txt_prop); | |
+ XFree(txt_prop.value); | |
+ | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_PID", False), | |
+ XInternAtom(dpy, "CARDINAL", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&cur_pid, | |
+ 1 | |
+ ); | |
+ | |
+ } | |
+ free(host_name); | |
+ | |
+ | |
+ XGetWindowAttributes(dpy, w, &wa); | |
+#ifdef DZEN_XINERAMA | |
+ queryscreeninfo(dpy,&si,dzen.xinescreen); | |
+#else | |
+ qsi_no_xinerama(dpy,&si); | |
+#endif | |
+ if(wa.y - si.y == 0) { | |
+ strut[2] = si.y + wa.height; | |
strut[8] = wa.x; | |
strut[9] = wa.x + wa.width - 1; | |
- } | |
- else if((wa.y + wa.height) == DisplayHeight(dpy, DefaultScreen(dpy))) { | |
+ | |
+ strut_s[2] = strut[2]; | |
+ } | |
+ else if((wa.y - si.y + wa.height) == si.height) { | |
+#ifdef DZEN_XINERAMA | |
+ max_height = si.height; | |
+ xsi = XineramaQueryScreens(dpy,&screen_count); | |
+ for(i=0; i < screen_count; i++) { | |
+ if(xsi[i].height > max_height) | |
+ max_height = xsi[i].height; | |
+ } | |
+ XFree(xsi); | |
+ /* Adjust strut value if there is a larger screen */ | |
+ strut[3] = max_height - (si.height + si.y) + wa.height; | |
+#else | |
strut[3] = wa.height; | |
+#endif | |
strut[10] = wa.x; | |
strut[11] = wa.x + wa.width - 1; | |
+ | |
+ strut_s[3] = strut[3]; | |
} | |
if(strut[2] != 0 || strut[3] != 0) { | |
XChangeProperty( | |
- dpy, | |
- w, | |
- XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False), | |
- XInternAtom(dpy, "CARDINAL", False), | |
- 32, | |
- PropModeReplace, | |
- (unsigned char *)&strut, | |
- 12 | |
- ); | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False), | |
+ XInternAtom(dpy, "CARDINAL", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&strut, | |
+ 12 | |
+ ); | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_STRUT", False), | |
+ XInternAtom(dpy, "CARDINAL", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&strut, | |
+ 4 | |
+ ); | |
} | |
+ | |
+ if(dock) { | |
+ type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False), | |
+ XInternAtom(dpy, "ATOM", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&type, | |
+ 1 | |
+ ); | |
+ | |
+ /* some window managers honor this properties*/ | |
+ type = XInternAtom(dpy, "_NET_WM_STATE_ABOVE", False); | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_STATE", False), | |
+ XInternAtom(dpy, "ATOM", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&type, | |
+ 1 | |
+ ); | |
+ | |
+ type = XInternAtom(dpy, "_NET_WM_STATE_STICKY", False); | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_STATE", False), | |
+ XInternAtom(dpy, "ATOM", False), | |
+ 32, | |
+ PropModeAppend, | |
+ (unsigned char *)&type, | |
+ 1 | |
+ ); | |
+ | |
+ | |
+ desktop = 0xffffffff; | |
+ XChangeProperty( | |
+ dpy, | |
+ w, | |
+ XInternAtom(dpy, "_NET_WM_DESKTOP", False), | |
+ XInternAtom(dpy, "CARDINAL", False), | |
+ 32, | |
+ PropModeReplace, | |
+ (unsigned char *)&desktop, | |
+ 1 | |
+ ); | |
+ } | |
+ | |
} | |
static void | |
@@ -322,7 +440,7 @@ | |
} | |
static void | |
-x_create_windows(void) { | |
+x_create_windows(int use_ewmh_dock) { | |
XSetWindowAttributes wa; | |
Window root; | |
int i; | |
@@ -345,7 +463,7 @@ | |
x_create_gcs(); | |
/* window attributes */ | |
- wa.override_redirect = 1; | |
+ wa.override_redirect = (use_ewmh_dock ? 0 : 1); | |
wa.background_pixmap = ParentRelative; | |
wa.event_mask = ExposureMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | KeyPressMask; | |
@@ -369,7 +487,7 @@ | |
XFillRectangle(dzen.dpy, dzen.title_win.drawable, dzen.rgc, 0, 0, dzen.title_win.width, dzen.line_height); | |
/* set some hints for windowmanagers*/ | |
- set_net_wm_strut_partial_for(dzen.dpy, dzen.title_win.win); | |
+ set_docking_ewmh_info(dzen.dpy, dzen.title_win.win, use_ewmh_dock); | |
/* TODO: Smarter approach to window creation so we can reduce the | |
* size of this function. | |
@@ -675,7 +793,7 @@ | |
int | |
main(int argc, char *argv[]) { | |
- int i; | |
+ int i, use_ewmh_dock=0; | |
char *action_string = NULL; | |
char *endptr; | |
@@ -760,6 +878,8 @@ | |
if(++i < argc) dzen.xinescreen = atoi(argv[i]); | |
} | |
#endif | |
+ else if(!strncmp(argv[i], "-dock", 6)) | |
+ use_ewmh_dock = 1; | |
else if(!strncmp(argv[i], "-v", 3)) | |
eprint("dzen-"VERSION", (C)opyright 2007 Robert Manea\n"); | |
else | |
@@ -769,6 +889,7 @@ | |
#ifdef DZEN_XINERAMA | |
" [-xs <screen>]\n" | |
#endif | |
+ " [-dock]\n" | |
); | |
if(dzen.tsupdate && !dzen.slave_win.max_lines) | |
@@ -827,7 +948,7 @@ | |
!dzen.slave_win.max_lines) | |
dzen.slave_win.max_lines = 1; | |
- x_create_windows(); | |
+ x_create_windows(use_ewmh_dock); | |
if(!dzen.slave_win.ishmenu) | |
x_map_window(dzen.title_win.win); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment