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>
101 unsigned short red, green, blue;
103 {0xd75c, 0xd75c, 0xe75c}, /* 0. light gray */
104 {0xbefb, 0xbaea, 0xcefb}, /* 1. mid gray */
105 {0xaefb, 0xaaea, 0xfefb}, /* 2. dark gray */
106 {0xefbe, 0xefbe, 0xffbe}, /* 3. white */
107 {0x8617, 0x8207, 0x9617}, /* 4. darkest gray */
108 {0x0000, 0x0000, 0x1000}, /* 5. black */
111 #define PALETTE_COUNT (sizeof (cols) / sizeof (cols[0].red) / 3)
113 unsigned long palette[PALETTE_COUNT];
115 char *atom_names[] = {
121 "_NET_WM_STATE_SKIP_TASKBAR",
122 "_NET_WM_STATE_SHADED",
123 "_NET_WM_STATE_BELOW",
124 "_NET_WM_STATE_HIDDEN",
126 "_NET_WM_WINDOW_TYPE",
127 "_NET_WM_WINDOW_TYPE_DOCK",
132 "_NET_CLIENT_LIST_STACKING",
133 "_NET_NUMBER_OF_DESKTOPS",
134 "_NET_CURRENT_DESKTOP",
138 "_NET_ACTIVE_WINDOW",
139 "_NET_RESTACK_WINDOW",
148 _NET_WM_STATE_SKIP_TASKBAR,
149 _NET_WM_STATE_SHADED,
151 _NET_WM_STATE_HIDDEN,
154 _NET_WM_WINDOW_TYPE_DOCK,
158 _NET_CLIENT_LIST_STACKING,
159 _NET_NUMBER_OF_DESKTOPS,
160 _NET_CURRENT_DESKTOP,
170 Atom atoms[ATOM_COUNT];
178 void *get_prop_data(Window win, Atom prop, Atom type, int *items)
182 unsigned long items_ret;
183 unsigned long after_ret;
184 unsigned char *prop_data;
188 XGetWindowProperty(dd, win, prop, 0, 0x7fffffff, False, type, &type_ret,
189 &format_ret, &items_ret, &after_ret, &prop_data);
196 void set_foreground(int index)
198 XSetForeground(dd, fore_gc, palette[index]);
201 void draw_line(int x, int y, int a, int b)
203 XDrawLine(dd, tb.win, fore_gc, x, y, a, b);
206 void fill_rect(int x, int y, int a, int b)
208 XFillRectangle(dd, tb.win, fore_gc, x, y, a, b);
211 void scale_icon(task * tk)
214 unsigned int w, h, d, bw;
215 Pixmap pix, mk = None;
219 XGetGeometry(dd, tk->icon, &pix, &x, &y, &w, &h, &bw, &d);
220 pix = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, scr_depth);
222 if (tk->mask != None) {
223 mk = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, 1);
224 gcv.subwindow_mode = IncludeInferiors;
225 gcv.graphics_exposures = False;
226 mgc = XCreateGC(dd, mk, GCGraphicsExposures | GCSubwindowMode, &gcv);
231 /* this is my simple & dirty scaling routine */
232 for (y = ICONHEIGHT - 1; y >= 0; y--) {
233 yy = (y * h) / ICONHEIGHT;
234 for (x = ICONWIDTH - 1; x >= 0; x--) {
235 xx = (x * w) / ICONWIDTH;
237 XCopyPlane(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y, 1);
239 XCopyArea(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y);
241 XCopyArea(dd, tk->mask, mk, mgc, xx, yy, 1, 1, x, y);
253 void get_task_hinticon(task * tk)
257 if (tk->icon != None && tk->icon != generic_icon)
258 if (tk->icon_copied) {
259 XFreePixmap(dd, tk->icon);
260 if (tk->mask != None && tk->mask != generic_mask)
261 XFreePixmap(dd, tk->mask);
267 hin = (XWMHints *)get_prop_data(tk->win, XA_WM_HINTS, XA_WM_HINTS, 0);
269 if ((hin->flags & IconPixmapHint)) {
270 if ((hin->flags & IconMaskHint)) {
271 tk->mask = hin->icon_mask;
274 tk->icon = hin->icon_pixmap;
281 if (tk->icon == None) {
282 tk->icon = generic_icon;
283 if (tk->mask != None)
284 XFreePixmap(dd, tk->mask);
285 tk->mask = generic_mask;
289 void get_task_kdeicon(task * tk)
293 data = get_prop_data(tk->win, atoms[KWM_WIN_ICON], atoms[KWM_WIN_ICON], 0);
301 int generic_get_int(Window win, Atom at)
306 data = get_prop_data(win, at, XA_CARDINAL, 0);
314 int find_desktop(Window win)
316 return generic_get_int(win, atoms[_NET_WM_DESKTOP]);
319 int find_state(Window win, atom_t atom)
325 data = get_prop_data(win, atoms[_NET_WM_STATE], XA_ATOM, &num);
328 if ((data[num]) == atoms[atom])
336 /* this naming is very confusing :) */
337 int is_hidden(Window win)
339 return find_state(win, _NET_WM_STATE_SKIP_TASKBAR);
342 int is_iconified(Window win)
344 return find_state(win, _NET_WM_STATE_HIDDEN);
347 int is_shaded(Window win)
349 return find_state(win, _NET_WM_STATE_SHADED);
352 int get_current_desktop(void)
354 return generic_get_int(root_win, atoms[_NET_CURRENT_DESKTOP]);
357 int get_number_of_desktops(void)
359 return generic_get_int(root_win, atoms[_NET_NUMBER_OF_DESKTOPS]);
362 void add_task(Window win, int focus)
370 /* is this window on a different desktop? */
371 desk = find_desktop(win);
372 if ((desk != 0xffffffff && tb.my_desktop != desk) || is_hidden(win))
375 tk = calloc(1, sizeof(task));
378 tk->name = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
379 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
380 // tk->name = get_prop_data(win, XA_WM_NAME, XA_STRING, 0);
381 //tk->locale = get_prop_data(win, XA_WM_LOCALE_NAME, XA_STRING, 0);
382 tk->iconified = is_iconified(win);
383 tk->shaded = is_shaded(win);
385 get_task_kdeicon(tk);
386 if (tk->icon == None)
387 get_task_hinticon(tk);
389 XSelectInput(dd, win, PropertyChangeMask | FocusChangeMask
390 | StructureNotifyMask);
392 /* now append it to our linked list */
409 void set_prop(Window win, Atom at, Atom type, long val)
411 XChangeProperty(dd, win, at, type, 32,
412 PropModeReplace, (unsigned char *)&val, 1);
415 Window gui_create_taskbar(void)
419 XSizeHints size_hints;
421 XSetWindowAttributes att;
424 att.background_pixel = palette[0];
425 att.event_mask = ButtonPressMask | ExposureMask;
427 win = rspanelwin = XCreateWindow(/* display */ dd,
428 /* parent */ root_win,
430 /* y */ scr_height - WINHEIGHT,
431 /* XXX Maybe just use scr_width here? */
432 /* width */ WINWIDTH,
433 /* height */ WINHEIGHT,
435 /* depth */ CopyFromParent,
436 /* class */ InputOutput,
437 /* visual */ CopyFromParent,
438 /*value mask*/ CWBackPixel | CWEventMask,
441 /* reside on ALL desktops */
442 set_prop(win, atoms[_NET_WM_DESKTOP], XA_CARDINAL, 0xFFFFFFFF);
443 set_prop(win, atoms[_NET_WM_WINDOW_TYPE], XA_ATOM,
444 atoms[_NET_WM_WINDOW_TYPE_DOCK]);
445 set_prop(win, atoms[_NET_WM_STATE], XA_ATOM, atoms[_NET_WM_STATE_BELOW]);
446 /* use old gnome hint since sawfish doesn't support _NET_WM_STRUT */
447 set_prop(win, atoms[_WIN_HINTS], XA_CARDINAL,
448 WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST |
449 WIN_HINTS_SKIP_TASKBAR | WIN_HINTS_DO_NOT_COVER);
450 XChangeProperty(dd, win, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
451 (unsigned char *)"rspanel", 7);
453 /* borderless motif hint */
454 bzero(&mwm, sizeof(mwm));
455 mwm.flags = MWM_HINTS_DECORATIONS;
456 XChangeProperty(dd, win, atoms[_MOTIF_WM_HINTS], atoms[_MOTIF_WM_HINTS], 32,
457 PropModeReplace, (unsigned char *)&mwm,
458 sizeof(MWMHints) / 4);
460 /* make sure the WM obays our window position */
461 size_hints.flags = PPosition;
462 /*XSetWMNormalHints (dd, win, &size_hints); */
463 XChangeProperty(dd, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
464 PropModeReplace, (unsigned char *)&size_hints,
465 sizeof(XSizeHints) / 4);
467 /* make our window unfocusable */
468 wmhints.flags = InputHint;
469 wmhints.input = False;
470 /*XSetWMHints (dd, win, &wmhints); */
471 XChangeProperty(dd, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace,
472 (unsigned char *)&wmhints, sizeof(XWMHints) / 4);
474 xclhints.res_name = "rspanel";
475 xclhints.res_class = "RSPanel";
476 XSetClassHint(dd, win, &xclhints);
481 xftdraw = XftDrawCreate(dd, win, DefaultVisual(dd, scr_screen),
482 DefaultColormap(dd, scr_screen));
500 PangoContext *context;
501 PangoFontDescription *pfd;
506 xcl.red = cols[i].red;
507 xcl.green = cols[i].green;
508 xcl.blue = cols[i].blue;
509 XAllocColor(dd, DefaultColormap(dd, scr_screen), &xcl);
510 palette[i] = xcl.pixel;
512 } while (i < PALETTE_COUNT);
516 xfs = XftFontOpenName(dd, scr_screen, XFT_FONT);
518 fontname = FONT_NAME;
520 xfs = XLoadQueryFont(dd, fontname);
525 gcv.graphics_exposures = False;
528 text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2);
529 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
531 text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2);
533 fore_gc = XCreateGC(dd, root_win, GCFont | GCGraphicsExposures, &gcv);
536 pfd = pango_font_description_new();
537 pango_font_description_set_absolute_size(pfd, PANGO_FONT_SIZE*PANGO_SCALE);
538 pango_font_description_set_family(pfd, PANGO_FONT_PREF);
539 context = pango_xft_get_context(dd, root_win);
540 pango_context_set_font_description(context, pfd);
541 pl = pango_layout_new(context);
543 pango_layout_set_single_paragraph_mode(pl, TRUE);
544 pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_END);
546 text_y = (WINHEIGHT*PANGO_SCALE-7*PANGO_SCALE);
547 pango_font_description_free(pfd);
548 g_object_unref(context);
550 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
554 XpmCreatePixmapFromData(dd, root_win, icon_xpm, &generic_icon,
555 &generic_mask, NULL);
560 inst = RrInstanceNew(dd, scr_screen);
561 theme = RrThemeNew(inst, "Mikachu", TRUE, NULL, NULL, NULL, NULL, NULL);
565 void gui_draw_vline(int x)
568 draw_line(x, 0, x, WINHEIGHT);
570 draw_line(x + 1, 0, x + 1, WINHEIGHT);
573 void draw_box(int x, int width)
575 set_foreground(1); /* mid gray */
576 fill_rect(x + 3, 2, width - 2, WINHEIGHT - 4);
578 set_foreground(3); /* white */
579 draw_line(x + 3, WINHEIGHT - 2, x + width - 1, WINHEIGHT - 2);
580 draw_line(x + width - 1, 1, x + width - 1, WINHEIGHT - 2);
582 set_foreground(4); /* darkest gray */
583 draw_line(x + 3, 1, x + width - 1, 1);
584 draw_line(x + 3, 2, x + 3, WINHEIGHT - 3);
589 void gui_draw_task(task *tk)
591 RrAppearance *a = tk->focused ? theme->a_focused_label : theme->a_unfocused_label;
592 RrAppearance *b = tk->focused ? theme->a_focused_title : theme->a_unfocused_title;
593 a->surface.parent = b;
594 a->surface.parentx = PADDING;
595 a->texture[0].data.text.string = tk->name;
596 RrPaintPixmap(b, tk->width, WINHEIGHT);
597 RrPaintPixmap(a, tk->width-2*PADDING, WINHEIGHT);
599 XCopyArea(dd, a->pixmap, b->pixmap, RrColorGC(b->surface.primary), 0, 0, tk->width-2*PADDING, WINHEIGHT, PADDING, 0);
600 XCopyArea(dd, b->pixmap, tb.win, RrColorGC(b->surface.primary), 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
602 XCopyArea(dd, a->pixmap, tb.win, RrColorGC(b->surface.primary), 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
605 XFreePixmap(dd, a->pixmap);
606 XFreePixmap(dd, b->pixmap);
609 void gui_draw_task(task * tk)
612 int taskw = tk->width;
626 set_foreground(0); /* mid gray */
627 fill_rect(x + 2, 0, taskw - 1, WINHEIGHT);
631 int text_x = x + TEXTPAD + TEXTPAD + (tk->icon ? ICONWIDTH : -1*ICONWIDTH/4);
632 #define SETCOL(x) col.color.red = cols[x].red;\
633 col.color.green = cols[x].green;\
634 col.color.blue = cols[x].blue;
637 pango_layout_set_width(pl, /*-1);*/(taskw - text_x + x) * PANGO_SCALE);
638 pango_layout_set_text(pl, tk->name, -1);
639 col.color.alpha = 0xffff;
643 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x+2)*PANGO_SCALE, text_y + 2);
645 } else if (tk->shaded) {
647 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x-2)*PANGO_SCALE, text_y - 2);
652 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), text_x*PANGO_SCALE, text_y);
656 /* check how many chars can fit */
657 len = strlen(tk->name);
659 XftTextExtentsUtf8(dd, xfs, tk->name, len, &ext);
660 if (ext.width < taskw - (text_x - x) - 2 || len <= 0)
665 col.color.alpha = 0xffff;
668 /* draw task's name dark (iconified) */
670 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y + 1, tk->name,
673 } else if (tk->shaded) {
674 /* draw task's name dark (shaded) */
676 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y - 1, tk->name,
684 /* draw task's name here */
685 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y, tk->name, len);
688 /* check how many chars can fit */
689 len = strlen(tk->name);
691 while (XTextWidth(xfs, tk->name, len) >= taskw - (text_x - x) - 2
696 /* draw task's name dark (iconified) */
698 XDrawString(dd, tb.win, fore_gc, text_x, text_y + 1, tk->name,
701 } else if (tk->shaded) {
702 /* draw task's name dark (shaded) */
704 XDrawString(dd, tb.win, fore_gc, text_x, text_y - 1, tk->name,
711 /* draw task's name here */
712 XDrawString(dd, tb.win, fore_gc, text_x, text_y, tk->name, len);
721 /* draw the task's icon */
722 XSetClipMask(dd, fore_gc, tk->mask);
723 XSetClipOrigin(dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
724 XCopyArea(dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT,
725 x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
726 XSetClipMask(dd, fore_gc, None);
730 void draw_dot(int x, int y)
733 XDrawPoint(dd, tb.win, fore_gc, x, y);
735 XDrawPoint(dd, tb.win, fore_gc, x + 1, y + 1);
738 void draw_grill(int x)
741 while (y < WINHEIGHT - 4) {
748 void netwm_action(Window win, atom_t atom, Time time, long l)
750 XClientMessageEvent xev = {
751 .type = ClientMessage,
755 .message_type = atoms[atom]
758 if (atom == _NET_ACTIVE_WINDOW) {
760 xev.data.l[1] = time;
762 } else if (atom == _NET_CURRENT_DESKTOP) {
764 xev.data.l[1] = time;
765 } else if (atom == _NET_RESTACK_WINDOW) {
768 } else if (atom == _OB_FOCUS) {
770 xev.message_type = atoms[_NET_WM_STATE];
772 xev.data.l[1] = atoms[atom];
776 XSendEvent(dd, root_win, False, SubstructureNotifyMask
777 |SubstructureRedirectMask, (XEvent *)&xev);
782 void switch_desk(int new_desk, Time time)
784 if (get_number_of_desktops() <= new_desk)
787 netwm_action(None, _NET_CURRENT_DESKTOP, time, new_desk);
790 /* This doesn't work with pango yet */
791 void pager_draw_button(int x, int num)
798 if (num == tb.my_desktop) {
799 /* current desktop */
800 draw_box(x, PAGER_BUTTON_WIDTH);
803 fill_rect(x, 1, PAGER_BUTTON_WIDTH + 1, WINHEIGHT - 2);
809 col.color.alpha = 0xffff;
810 col.color.red = cols[5].red;
811 col.color.green = cols[5].green;
812 col.color.blue = cols[5].blue;
813 XftDrawString8(xftdraw, &col, xfs,
814 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y,
818 XDrawString(dd, tb.win, fore_gc,
819 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1,
824 void pager_draw(void)
826 int desks, i, x = GRILL_WIDTH;
828 desks = get_number_of_desktops();
830 for (i = 0; i < desks; i++) {
831 pager_draw_button(x, i);
834 x += PAGER_BUTTON_WIDTH;
842 void gui_draw_taskbar(void)
850 pager_size = TEXTPAD;
853 width = WINWIDTH - (pager_size + GRILL_WIDTH + GRILL_WIDTH);
856 if (tb.num_tasks == 0)
859 taskw = width / tb.num_tasks;
860 if (taskw > MAX_TASK_WIDTH)
861 taskw = MAX_TASK_WIDTH;
866 tk->width = taskw - 1;
872 if (x < (width + pager_size + 2)) {
876 fill_rect(x + 2, 0, WINWIDTH, WINHEIGHT);
880 gui_draw_vline(WINWIDTH - 8);
883 draw_grill(WINWIDTH - 6);
886 task *find_task(Window win)
888 task *list = tb.task_list;
890 if (list->win == win)
897 void del_task(Window win)
899 task *next, *prev = 0, *list = tb.task_list;
903 if (list->win == win) {
904 /* unlink and free this task */
906 if (list->icon_copied) {
907 XFreePixmap(dd, list->icon);
908 if (list->mask != None)
909 XFreePixmap(dd, list->mask);
925 void move_taskbar(void)
932 x = TEXTPAD - WINWIDTH;
935 y = scr_height - WINHEIGHT;
937 XMoveWindow(dd, tb.win, x, y);
940 void taskbar_read_clientlist(void)
942 Window *win, focus_win = 0;
943 int num, i, desk, new_desk = 0;
945 desk = get_current_desktop();
952 XResizeWindow(dd, rspanelwin, WINWIDTH, WINHEIGHT);
955 if (desk != tb.my_desktop) {
957 tb.my_desktop = desk;
960 win = get_prop_data(root_win, atoms[_NET_ACTIVE_WINDOW], XA_WINDOW, &num);
964 win = get_prop_data(root_win, atoms[_NET_CLIENT_LIST], XA_WINDOW, &num);
968 /* remove windows that arn't in the _NET_CLIENT_LIST anymore */
971 list->focused = (focus_win == list->win);
975 for (i = num - 1; i >= 0; i--)
976 if (list->win == win[i] && !is_hidden(win[i]))
984 /* add any new windows */
985 for (i = 0; i < num; i++) {
986 if (!find_task(win[i]))
987 add_task(win[i], (win[i] == focus_win));
993 void handle_press(int x, int y, int button, Time time)
998 if ((y > 2 && y < WINHEIGHT - 2 && x > GRILL_WIDTH) && button == 1)
999 switch_desk((x - GRILL_WIDTH) / PAGER_BUTTON_WIDTH, time);
1002 /* clicked left grill */
1005 tb.at_top = 1 - tb.at_top;
1007 } else if (button == 4) {
1013 /* clicked right grill */
1014 else if (x + TEXTPAD > WINWIDTH) {
1015 if (tb.hidden && (button == 1 || button == 5)) {
1018 } else if (!tb.hidden && (button == 1 || button == 4)) {
1025 /* clicked on a task button */
1026 /* XXX Make this configureable */
1027 if (x > tk->pos_x && x < tk->pos_x + tk->width) {
1030 netwm_action(tk->win, _NET_ACTIVE_WINDOW, time, 0);
1034 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1036 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, ADD);
1039 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Opposite);
1042 if (is_shaded(tk->win))
1043 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1045 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, ADD);
1048 if (is_shaded(tk->win))
1049 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, REMOVE);
1051 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1055 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1057 netwm_action(tk->win, _OB_FOCUS, 0, 0);
1060 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1063 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1069 } /* clicked on the background */
1072 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Above);
1075 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Below);
1078 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Opposite);
1092 void handle_focusin(Window win)
1099 if (tk->win != win) {
1104 if (tk->win == win) {
1113 void handle_propertynotify(Window win, Atom at)
1117 if (win == root_win) {
1118 if (at == atoms[_NET_CLIENT_LIST] || at == atoms[_NET_CURRENT_DESKTOP] || at == atoms[_NET_CLIENT_LIST_STACKING]) {
1119 taskbar_read_clientlist();
1125 /* XXX make this work when SKIP_TASKBAR is toggled too */
1126 tk = find_task(win);
1130 if (at == XA_WM_NAME || at == atoms[_NET_WM_NAME]) {
1131 /* window's title changed */
1133 newname = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
1134 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
1136 if (tk->name && !strcmp(newname, tk->name)) {
1145 } else if (at == atoms[_NET_WM_STATE]) {
1146 /* iconified state changed? */
1147 if (is_iconified(tk->win) != tk->iconified) {
1148 tk->iconified = !tk->iconified;
1151 /* shaded state changed? */
1152 if (is_shaded(tk->win) != tk->shaded) {
1153 tk->shaded = !tk->shaded;
1156 } else if (at == XA_WM_HINTS) {
1157 /* some windows set their WM_HINTS icon after mapping */
1158 //if (tk->icon == generic_icon) {
1159 get_task_hinticon(tk);
1162 } else if (at == atoms[_NET_WM_DESKTOP]) {
1163 if (find_desktop(win) != get_current_desktop())
1168 void handle_error(Display * d, XErrorEvent * ev)
1176 main(int argc, char *argv[])
1181 dd = XOpenDisplay(NULL);
1184 scr_screen = DefaultScreen(dd);
1185 scr_depth = DefaultDepth(dd, scr_screen);
1186 scr_height = DisplayHeight(dd, scr_screen);
1187 scr_width = DisplayWidth(dd, scr_screen);
1188 root_win = RootWindow(dd, scr_screen);
1190 /* helps us catch windows closing/opening */
1191 XSelectInput(dd, root_win, PropertyChangeMask);
1193 XSetErrorHandler((XErrorHandler) handle_error);
1195 XInternAtoms(dd, atom_names, ATOM_COUNT, False, atoms);
1198 memset(&tb, 0, sizeof(tb));
1199 tb.win = gui_create_taskbar();
1202 while (XNextEvent(dd, &ev) == Success) {
1205 handle_press(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.time);
1208 del_task(ev.xdestroywindow.window);
1213 case PropertyNotify:
1214 handle_propertynotify(ev.xproperty.window, ev.xproperty.atom);
1217 if (ev.xfocus.mode != NotifyGrab)
1218 handle_focusin(ev.xfocus.window);
1221 printf ("unknown evt type: %d\n", ev.type); */
1224 /* RrThemeFree(theme);
1225 * RrInstanceFree(inst);
1226 * XCloseDisplay (dd);