2 /**********************************************************
3 ** Rather Small Panel 0.8beta1 Copyright (c) 2006 **
4 ** By Mikael Magnusson **
5 ** See file COPYING for license details. **
6 **********************************************************/
12 #include <sys/types.h>
16 #include <X11/Xutil.h>
17 #include <X11/Xatom.h>
26 /* you can edit these */
27 #define MAX_TASK_WIDTH 500
32 # define WINWIDTH 1280
36 #define FONT_NAME "-*-Technical*-m*-r-*-*-14-*-*"
37 #define XFT_FONT "Arial Unicode MS-12"
38 #define PANGO_FONT_PREF "Utopia"
39 //#define PANGO_FONT_PREF "Technical"
40 #define PANGO_FONT_SIZE 13
41 //#define PAGER /* use a desktop pager? */
42 #define PAGER_DIGIT_WIDTH 6
43 #define PAGER_BUTTON_WIDTH 20
48 /* don't edit these */
50 #define GRILL_WIDTH 10
55 #include <pango/pango.h>
56 #include <pango/pangoxft.h>
59 #include <X11/Xft/Xft.h>
64 #include <openbox/render.h>
65 #include <openbox/theme.h>
96 unsigned short red, green, blue;
98 {0xd75c, 0xd75c, 0xe75c}, /* 0. light gray */
99 {0xbefb, 0xbaea, 0xcefb}, /* 1. mid gray */
100 {0xaefb, 0xaaea, 0xfefb}, /* 2. dark gray */
101 {0xefbe, 0xefbe, 0xffbe}, /* 3. white */
102 {0x8617, 0x8207, 0x9617}, /* 4. darkest gray */
103 {0x0000, 0x0000, 0x1000}, /* 5. black */
106 #define PALETTE_COUNT (sizeof (cols) / sizeof (cols[0].red) / 3)
108 unsigned long palette[PALETTE_COUNT];
110 char *atom_names[] = {
116 "_NET_WM_STATE_SKIP_TASKBAR",
117 "_NET_WM_STATE_SHADED",
118 "_NET_WM_STATE_BELOW",
119 "_NET_WM_STATE_HIDDEN",
121 "_NET_WM_WINDOW_TYPE",
122 "_NET_WM_WINDOW_TYPE_DOCK",
127 "_NET_CLIENT_LIST_STACKING",
128 "_NET_NUMBER_OF_DESKTOPS",
129 "_NET_CURRENT_DESKTOP",
133 "_NET_ACTIVE_WINDOW",
134 "_NET_RESTACK_WINDOW",
142 _NET_WM_STATE_SKIP_TASKBAR,
143 _NET_WM_STATE_SHADED,
145 _NET_WM_STATE_HIDDEN,
148 _NET_WM_WINDOW_TYPE_DOCK,
152 _NET_CLIENT_LIST_STACKING,
153 _NET_NUMBER_OF_DESKTOPS,
154 _NET_CURRENT_DESKTOP,
163 Atom atoms[ATOM_COUNT];
171 void *get_prop_data(Window win, Atom prop, Atom type, int *items)
175 unsigned long items_ret;
176 unsigned long after_ret;
177 unsigned char *prop_data;
181 XGetWindowProperty(dd, win, prop, 0, 0x7fffffff, False, type, &type_ret,
182 &format_ret, &items_ret, &after_ret, &prop_data);
189 void set_foreground(int index)
191 XSetForeground(dd, fore_gc, palette[index]);
194 void draw_line(int x, int y, int a, int b)
196 XDrawLine(dd, tb.win, fore_gc, x, y, a, b);
199 void fill_rect(int x, int y, int a, int b)
201 XFillRectangle(dd, tb.win, fore_gc, x, y, a, b);
204 void scale_icon(task * tk)
207 unsigned int w, h, d, bw;
208 Pixmap pix, mk = None;
212 XGetGeometry(dd, tk->icon, &pix, &x, &y, &w, &h, &bw, &d);
213 pix = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, scr_depth);
215 if (tk->mask != None) {
216 mk = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, 1);
217 gcv.subwindow_mode = IncludeInferiors;
218 gcv.graphics_exposures = False;
219 mgc = XCreateGC(dd, mk, GCGraphicsExposures | GCSubwindowMode, &gcv);
224 /* this is my simple & dirty scaling routine */
225 for (y = ICONHEIGHT - 1; y >= 0; y--) {
226 yy = (y * h) / ICONHEIGHT;
227 for (x = ICONWIDTH - 1; x >= 0; x--) {
228 xx = (x * w) / ICONWIDTH;
230 XCopyPlane(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y, 1);
232 XCopyArea(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y);
234 XCopyArea(dd, tk->mask, mk, mgc, xx, yy, 1, 1, x, y);
246 void get_task_hinticon(task * tk)
250 if (tk->icon != None && tk->icon != generic_icon)
251 if (tk->icon_copied) {
252 XFreePixmap(dd, tk->icon);
253 if (tk->mask != None && tk->mask != generic_mask)
254 XFreePixmap(dd, tk->mask);
260 hin = (XWMHints *)get_prop_data(tk->win, XA_WM_HINTS, XA_WM_HINTS, 0);
262 if ((hin->flags & IconPixmapHint)) {
263 if ((hin->flags & IconMaskHint)) {
264 tk->mask = hin->icon_mask;
267 tk->icon = hin->icon_pixmap;
274 if (tk->icon == None) {
275 tk->icon = generic_icon;
276 if (tk->mask != None)
277 XFreePixmap(dd, tk->mask);
278 tk->mask = generic_mask;
282 void get_task_kdeicon(task * tk)
286 data = get_prop_data(tk->win, atoms[KWM_WIN_ICON], atoms[KWM_WIN_ICON], 0);
294 int generic_get_int(Window win, Atom at)
299 data = get_prop_data(win, at, XA_CARDINAL, 0);
307 int find_desktop(Window win)
309 return generic_get_int(win, atoms[_NET_WM_DESKTOP]);
312 int find_state(Window win, atom_t atom)
318 data = get_prop_data(win, atoms[_NET_WM_STATE], XA_ATOM, &num);
321 if ((data[num]) == atoms[atom])
329 /* this naming is very confusing :) */
330 int is_hidden(Window win)
332 return find_state(win, _NET_WM_STATE_SKIP_TASKBAR);
335 int is_iconified(Window win)
337 return find_state(win, _NET_WM_STATE_HIDDEN);
340 int is_shaded(Window win)
342 return find_state(win, _NET_WM_STATE_SHADED);
345 int get_current_desktop(void)
347 return generic_get_int(root_win, atoms[_NET_CURRENT_DESKTOP]);
350 int get_number_of_desktops(void)
352 return generic_get_int(root_win, atoms[_NET_NUMBER_OF_DESKTOPS]);
355 void add_task(Window win, int focus)
363 /* is this window on a different desktop? */
364 desk = find_desktop(win);
365 if ((desk != 0xffffffff && tb.my_desktop != desk) || is_hidden(win))
368 tk = calloc(1, sizeof(task));
371 tk->name = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
372 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
373 // tk->name = get_prop_data(win, XA_WM_NAME, XA_STRING, 0);
374 //tk->locale = get_prop_data(win, XA_WM_LOCALE_NAME, XA_STRING, 0);
375 tk->iconified = is_iconified(win);
376 tk->shaded = is_shaded(win);
378 get_task_kdeicon(tk);
379 if (tk->icon == None)
380 get_task_hinticon(tk);
382 XSelectInput(dd, win, PropertyChangeMask | FocusChangeMask
383 | StructureNotifyMask);
385 /* now append it to our linked list */
402 void set_prop(Window win, Atom at, Atom type, long val)
404 XChangeProperty(dd, win, at, type, 32,
405 PropModeReplace, (unsigned char *)&val, 1);
408 Window gui_create_taskbar(void)
412 XSizeHints size_hints;
414 XSetWindowAttributes att;
417 att.background_pixel = palette[0];
418 att.event_mask = ButtonPressMask | ExposureMask;
420 win = rspanelwin = XCreateWindow(/* display */ dd,
421 /* parent */ root_win,
423 /* y */ scr_height - WINHEIGHT,
424 /* XXX Maybe just use scr_width here? */
425 /* width */ WINWIDTH,
426 /* height */ WINHEIGHT,
428 /* depth */ CopyFromParent,
429 /* class */ InputOutput,
430 /* visual */ CopyFromParent,
431 /*value mask*/ CWBackPixel | CWEventMask,
434 /* reside on ALL desktops */
435 set_prop(win, atoms[_NET_WM_DESKTOP], XA_CARDINAL, 0xFFFFFFFF);
436 set_prop(win, atoms[_NET_WM_WINDOW_TYPE], XA_ATOM,
437 atoms[_NET_WM_WINDOW_TYPE_DOCK]);
438 set_prop(win, atoms[_NET_WM_STATE], XA_ATOM, atoms[_NET_WM_STATE_BELOW]);
439 /* use old gnome hint since sawfish doesn't support _NET_WM_STRUT */
440 set_prop(win, atoms[_WIN_HINTS], XA_CARDINAL,
441 WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST |
442 WIN_HINTS_SKIP_TASKBAR | WIN_HINTS_DO_NOT_COVER);
443 XChangeProperty(dd, win, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
444 (unsigned char *)"rspanel", 7);
446 /* borderless motif hint */
447 bzero(&mwm, sizeof(mwm));
448 mwm.flags = MWM_HINTS_DECORATIONS;
449 XChangeProperty(dd, win, atoms[_MOTIF_WM_HINTS], atoms[_MOTIF_WM_HINTS], 32,
450 PropModeReplace, (unsigned char *)&mwm,
451 sizeof(MWMHints) / 4);
453 /* make sure the WM obays our window position */
454 size_hints.flags = PPosition;
455 /*XSetWMNormalHints (dd, win, &size_hints); */
456 XChangeProperty(dd, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
457 PropModeReplace, (unsigned char *)&size_hints,
458 sizeof(XSizeHints) / 4);
460 /* make our window unfocusable */
461 wmhints.flags = InputHint;
462 wmhints.input = False;
463 /*XSetWMHints (dd, win, &wmhints); */
464 XChangeProperty(dd, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace,
465 (unsigned char *)&wmhints, sizeof(XWMHints) / 4);
467 xclhints.res_name = "rspanel";
468 xclhints.res_class = "RSPanel";
469 XSetClassHint(dd, win, &xclhints);
474 xftdraw = XftDrawCreate(dd, win, DefaultVisual(dd, scr_screen),
475 DefaultColormap(dd, scr_screen));
493 PangoContext *context;
494 PangoFontDescription *pfd;
499 xcl.red = cols[i].red;
500 xcl.green = cols[i].green;
501 xcl.blue = cols[i].blue;
502 XAllocColor(dd, DefaultColormap(dd, scr_screen), &xcl);
503 palette[i] = xcl.pixel;
505 } while (i < PALETTE_COUNT);
509 xfs = XftFontOpenName(dd, scr_screen, XFT_FONT);
511 fontname = FONT_NAME;
513 xfs = XLoadQueryFont(dd, fontname);
518 gcv.graphics_exposures = False;
521 text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2);
522 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
524 text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2);
526 fore_gc = XCreateGC(dd, root_win, GCFont | GCGraphicsExposures, &gcv);
529 pfd = pango_font_description_new();
530 pango_font_description_set_absolute_size(pfd, PANGO_FONT_SIZE*PANGO_SCALE);
531 pango_font_description_set_family(pfd, PANGO_FONT_PREF);
532 context = pango_xft_get_context(dd, root_win);
533 pango_context_set_font_description(context, pfd);
534 pl = pango_layout_new(context);
536 pango_layout_set_single_paragraph_mode(pl, TRUE);
537 pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_END);
539 text_y = (WINHEIGHT*PANGO_SCALE-7*PANGO_SCALE);
540 pango_font_description_free(pfd);
541 g_object_unref(context);
543 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
547 XpmCreatePixmapFromData(dd, root_win, icon_xpm, &generic_icon,
548 &generic_mask, NULL);
554 void gui_draw_vline(int x)
557 draw_line(x, 0, x, WINHEIGHT);
559 draw_line(x + 1, 0, x + 1, WINHEIGHT);
562 void draw_box(int x, int width)
564 set_foreground(1); /* mid gray */
565 fill_rect(x + 3, 2, width - 2, WINHEIGHT - 4);
567 set_foreground(3); /* white */
568 draw_line(x + 3, WINHEIGHT - 2, x + width - 1, WINHEIGHT - 2);
569 draw_line(x + width - 1, 1, x + width - 1, WINHEIGHT - 2);
571 set_foreground(4); /* darkest gray */
572 draw_line(x + 3, 1, x + width - 1, 1);
573 draw_line(x + 3, 2, x + 3, WINHEIGHT - 3);
577 void gui_draw_task(task *tk)
579 RrInstance *inst = RrInstanceNew(dd, scr_screen);
580 RrTheme *theme = RrThemeNew(inst, "Mikachu", TRUE, NULL, NULL, NULL, NULL, NULL);
581 RrAppearance *a = RrAppearanceCopy(theme->osd_hilite_label);
582 a->texture[0].type = RR_TEXTURE_TEXT;
583 a->texture[0].data.text.string = tk->name;
584 RrPaint(a, tb.win, WINWIDTH, WINHEIGHT);
586 RrInstanceFree(inst);
589 void gui_draw_task(task * tk)
592 int taskw = tk->width;
606 set_foreground(0); /* mid gray */
607 fill_rect(x + 2, 0, taskw - 1, WINHEIGHT);
611 int text_x = x + TEXTPAD + TEXTPAD + (tk->icon ? ICONWIDTH : -1*ICONWIDTH/4);
612 #define SETCOL(x) col.color.red = cols[x].red;\
613 col.color.green = cols[x].green;\
614 col.color.blue = cols[x].blue;
617 pango_layout_set_width(pl, /*-1);*/(taskw - text_x + x) * PANGO_SCALE);
618 pango_layout_set_text(pl, tk->name, -1);
619 col.color.alpha = 0xffff;
623 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x+2)*PANGO_SCALE, text_y + 2);
625 } else if (tk->shaded) {
627 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x-2)*PANGO_SCALE, text_y - 2);
632 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), text_x*PANGO_SCALE, text_y);
636 /* check how many chars can fit */
637 len = strlen(tk->name);
639 XftTextExtentsUtf8(dd, xfs, tk->name, len, &ext);
640 if (ext.width < taskw - (text_x - x) - 2 || len <= 0)
645 col.color.alpha = 0xffff;
648 /* draw task's name dark (iconified) */
650 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y + 1, tk->name,
653 } else if (tk->shaded) {
654 /* draw task's name dark (shaded) */
656 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y - 1, tk->name,
664 /* draw task's name here */
665 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y, tk->name, len);
668 /* check how many chars can fit */
669 len = strlen(tk->name);
671 while (XTextWidth(xfs, tk->name, len) >= taskw - (text_x - x) - 2
676 /* draw task's name dark (iconified) */
678 XDrawString(dd, tb.win, fore_gc, text_x, text_y + 1, tk->name,
681 } else if (tk->shaded) {
682 /* draw task's name dark (shaded) */
684 XDrawString(dd, tb.win, fore_gc, text_x, text_y - 1, tk->name,
691 /* draw task's name here */
692 XDrawString(dd, tb.win, fore_gc, text_x, text_y, tk->name, len);
701 /* draw the task's icon */
702 XSetClipMask(dd, fore_gc, tk->mask);
703 XSetClipOrigin(dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
704 XCopyArea(dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT,
705 x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
706 XSetClipMask(dd, fore_gc, None);
710 void draw_dot(int x, int y)
713 XDrawPoint(dd, tb.win, fore_gc, x, y);
715 XDrawPoint(dd, tb.win, fore_gc, x + 1, y + 1);
718 void draw_grill(int x)
721 while (y < WINHEIGHT - 4) {
728 #ifdef MIKACHU //this only works in mikabox
729 void ob_action(Window win, char *action)
731 XClientMessageEvent xev;
732 char act_name[14+strlen(action)];
733 sprintf(act_name, "_OB_WM_ACTION_%s", action);
735 xev.type = ClientMessage;
737 xev.message_type = atoms[_OB_WM_ACTION];
739 /*strncpy(xev.data.b, action, 20);*/
740 xev.data.l[0] = XInternAtom(dd, act_name, False);
741 XSendEvent(dd, root_win, False, SubstructureRedirectMask, (XEvent *)&xev);
744 void netwm_action(Window win, atom_t atom, Time time, long l)
746 XClientMessageEvent xev = {
747 .type = ClientMessage,
751 .message_type = atoms[atom]
754 if (atom == _NET_ACTIVE_WINDOW) {
756 xev.data.l[1] = time;
758 } else if (atom == _NET_CURRENT_DESKTOP) {
760 xev.data.l[1] = time;
761 } else if (atom == _NET_RESTACK_WINDOW) {
765 xev.message_type = atoms[_NET_WM_STATE];
767 xev.data.l[1] = atoms[atom];
771 XSendEvent(dd, root_win, False, SubstructureNotifyMask
772 |SubstructureRedirectMask, (XEvent *)&xev);
777 void switch_desk(int new_desk, Time time)
779 if (get_number_of_desktops() <= new_desk)
782 netwm_action(None, _NET_CURRENT_DESKTOP, time, new_desk);
785 /* This doesn't work with pango yet */
786 void pager_draw_button(int x, int num)
793 if (num == tb.my_desktop) {
794 /* current desktop */
795 draw_box(x, PAGER_BUTTON_WIDTH);
798 fill_rect(x, 1, PAGER_BUTTON_WIDTH + 1, WINHEIGHT - 2);
804 col.color.alpha = 0xffff;
805 col.color.red = cols[5].red;
806 col.color.green = cols[5].green;
807 col.color.blue = cols[5].blue;
808 XftDrawString8(xftdraw, &col, xfs,
809 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y,
813 XDrawString(dd, tb.win, fore_gc,
814 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1,
819 void pager_draw(void)
821 int desks, i, x = GRILL_WIDTH;
823 desks = get_number_of_desktops();
825 for (i = 0; i < desks; i++) {
826 pager_draw_button(x, i);
829 x += PAGER_BUTTON_WIDTH;
837 void gui_draw_taskbar(void)
845 pager_size = TEXTPAD;
848 width = WINWIDTH - (pager_size + GRILL_WIDTH + GRILL_WIDTH);
851 if (tb.num_tasks == 0)
854 taskw = width / tb.num_tasks;
855 if (taskw > MAX_TASK_WIDTH)
856 taskw = MAX_TASK_WIDTH;
861 tk->width = taskw - 1;
867 if (x < (width + pager_size + 2)) {
871 fill_rect(x + 2, 0, WINWIDTH, WINHEIGHT);
875 gui_draw_vline(WINWIDTH - 8);
878 draw_grill(WINWIDTH - 6);
881 task *find_task(Window win)
883 task *list = tb.task_list;
885 if (list->win == win)
892 void del_task(Window win)
894 task *next, *prev = 0, *list = tb.task_list;
898 if (list->win == win) {
899 /* unlink and free this task */
901 if (list->icon_copied) {
902 XFreePixmap(dd, list->icon);
903 if (list->mask != None)
904 XFreePixmap(dd, list->mask);
920 void move_taskbar(void)
927 x = TEXTPAD - WINWIDTH;
930 y = scr_height - WINHEIGHT;
932 XMoveWindow(dd, tb.win, x, y);
935 void taskbar_read_clientlist(void)
937 Window *win, focus_win = 0;
938 int num, i, desk, new_desk = 0;
940 desk = get_current_desktop();
947 XResizeWindow(dd, rspanelwin, WINWIDTH, WINHEIGHT);
950 if (desk != tb.my_desktop) {
952 tb.my_desktop = desk;
955 win = get_prop_data(root_win, atoms[_NET_ACTIVE_WINDOW], XA_WINDOW, &num);
959 win = get_prop_data(root_win, atoms[_NET_CLIENT_LIST], XA_WINDOW, &num);
963 /* remove windows that arn't in the _NET_CLIENT_LIST anymore */
966 list->focused = (focus_win == list->win);
970 for (i = num - 1; i >= 0; i--)
971 if (list->win == win[i] && !is_hidden(win[i]))
979 /* add any new windows */
980 for (i = 0; i < num; i++) {
981 if (!find_task(win[i]))
982 add_task(win[i], (win[i] == focus_win));
988 void handle_press(int x, int y, int button, Time time)
993 if ((y > 2 && y < WINHEIGHT - 2 && x > GRILL_WIDTH) && button == 1)
994 switch_desk((x - GRILL_WIDTH) / PAGER_BUTTON_WIDTH, time);
997 /* clicked left grill */
1000 tb.at_top = 1 - tb.at_top;
1002 } else if (button == 4) {
1008 /* clicked right grill */
1009 else if (x + TEXTPAD > WINWIDTH) {
1010 if (tb.hidden && (button == 1 || button == 5)) {
1013 } else if (!tb.hidden && (button == 1 || button == 4)) {
1020 /* clicked on a task button */
1021 /* XXX Make this configureable */
1022 if (x > tk->pos_x && x < tk->pos_x + tk->width) {
1025 netwm_action(tk->win, _NET_ACTIVE_WINDOW, time, 0);
1029 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1031 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, ADD);
1034 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Opposite);
1037 if (is_shaded(tk->win))
1038 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1040 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, ADD);
1043 if (is_shaded(tk->win))
1044 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, REMOVE);
1046 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1050 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1051 #ifdef MIKACHU //this doesn't work for anyone else anyway
1053 ob_action(tk->win, "focus");
1057 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1060 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1066 } /* clicked on the background */
1069 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Above);
1072 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Below);
1075 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Opposite);
1089 void handle_focusin(Window win)
1096 if (tk->win != win) {
1101 if (tk->win == win) {
1110 void handle_propertynotify(Window win, Atom at)
1114 if (win == root_win) {
1115 if (at == atoms[_NET_CLIENT_LIST] || at == atoms[_NET_CURRENT_DESKTOP] || at == atoms[_NET_CLIENT_LIST_STACKING]) {
1116 taskbar_read_clientlist();
1122 /* XXX make this work when SKIP_TASKBAR is toggled too */
1123 tk = find_task(win);
1127 if (at == XA_WM_NAME || at == atoms[_NET_WM_NAME]) {
1128 /* window's title changed */
1130 newname = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
1131 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
1133 if (tk->name && !strcmp(newname, tk->name)) {
1142 } else if (at == atoms[_NET_WM_STATE]) {
1143 /* iconified state changed? */
1144 if (is_iconified(tk->win) != tk->iconified) {
1145 tk->iconified = !tk->iconified;
1148 /* shaded state changed? */
1149 if (is_shaded(tk->win) != tk->shaded) {
1150 tk->shaded = !tk->shaded;
1153 } else if (at == XA_WM_HINTS) {
1154 /* some windows set their WM_HINTS icon after mapping */
1155 //if (tk->icon == generic_icon) {
1156 get_task_hinticon(tk);
1159 } else if (at == atoms[_NET_WM_DESKTOP]) {
1160 if (find_desktop(win) != get_current_desktop())
1165 void handle_error(Display * d, XErrorEvent * ev)
1173 main(int argc, char *argv[])
1178 dd = XOpenDisplay(NULL);
1181 scr_screen = DefaultScreen(dd);
1182 scr_depth = DefaultDepth(dd, scr_screen);
1183 scr_height = DisplayHeight(dd, scr_screen);
1184 scr_width = DisplayWidth(dd, scr_screen);
1185 root_win = RootWindow(dd, scr_screen);
1187 /* helps us catch windows closing/opening */
1188 XSelectInput(dd, root_win, PropertyChangeMask);
1190 XSetErrorHandler((XErrorHandler) handle_error);
1192 XInternAtoms(dd, atom_names, ATOM_COUNT, False, atoms);
1195 memset(&tb, 0, sizeof(tb));
1196 tb.win = gui_create_taskbar();
1199 while (XNextEvent(dd, &ev) == Success) {
1202 handle_press(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.time);
1205 del_task(ev.xdestroywindow.window);
1210 case PropertyNotify:
1211 handle_propertynotify(ev.xproperty.window, ev.xproperty.atom);
1214 if (ev.xfocus.mode != NotifyGrab)
1215 handle_focusin(ev.xfocus.window);
1218 printf ("unknown evt type: %d\n", ev.type); */
1222 /*XCloseDisplay (dd);