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",
147 _NET_WM_STATE_SKIP_TASKBAR,
148 _NET_WM_STATE_SHADED,
150 _NET_WM_STATE_HIDDEN,
153 _NET_WM_WINDOW_TYPE_DOCK,
157 _NET_CLIENT_LIST_STACKING,
158 _NET_NUMBER_OF_DESKTOPS,
159 _NET_CURRENT_DESKTOP,
168 Atom atoms[ATOM_COUNT];
176 void *get_prop_data(Window win, Atom prop, Atom type, int *items)
180 unsigned long items_ret;
181 unsigned long after_ret;
182 unsigned char *prop_data;
186 XGetWindowProperty(dd, win, prop, 0, 0x7fffffff, False, type, &type_ret,
187 &format_ret, &items_ret, &after_ret, &prop_data);
194 void set_foreground(int index)
196 XSetForeground(dd, fore_gc, palette[index]);
199 void draw_line(int x, int y, int a, int b)
201 XDrawLine(dd, tb.win, fore_gc, x, y, a, b);
204 void fill_rect(int x, int y, int a, int b)
206 XFillRectangle(dd, tb.win, fore_gc, x, y, a, b);
209 void scale_icon(task * tk)
212 unsigned int w, h, d, bw;
213 Pixmap pix, mk = None;
217 XGetGeometry(dd, tk->icon, &pix, &x, &y, &w, &h, &bw, &d);
218 pix = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, scr_depth);
220 if (tk->mask != None) {
221 mk = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, 1);
222 gcv.subwindow_mode = IncludeInferiors;
223 gcv.graphics_exposures = False;
224 mgc = XCreateGC(dd, mk, GCGraphicsExposures | GCSubwindowMode, &gcv);
229 /* this is my simple & dirty scaling routine */
230 for (y = ICONHEIGHT - 1; y >= 0; y--) {
231 yy = (y * h) / ICONHEIGHT;
232 for (x = ICONWIDTH - 1; x >= 0; x--) {
233 xx = (x * w) / ICONWIDTH;
235 XCopyPlane(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y, 1);
237 XCopyArea(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y);
239 XCopyArea(dd, tk->mask, mk, mgc, xx, yy, 1, 1, x, y);
251 void get_task_hinticon(task * tk)
255 if (tk->icon != None && tk->icon != generic_icon)
256 if (tk->icon_copied) {
257 XFreePixmap(dd, tk->icon);
258 if (tk->mask != None && tk->mask != generic_mask)
259 XFreePixmap(dd, tk->mask);
265 hin = (XWMHints *)get_prop_data(tk->win, XA_WM_HINTS, XA_WM_HINTS, 0);
267 if ((hin->flags & IconPixmapHint)) {
268 if ((hin->flags & IconMaskHint)) {
269 tk->mask = hin->icon_mask;
272 tk->icon = hin->icon_pixmap;
279 if (tk->icon == None) {
280 tk->icon = generic_icon;
281 if (tk->mask != None)
282 XFreePixmap(dd, tk->mask);
283 tk->mask = generic_mask;
287 void get_task_kdeicon(task * tk)
291 data = get_prop_data(tk->win, atoms[KWM_WIN_ICON], atoms[KWM_WIN_ICON], 0);
299 int generic_get_int(Window win, Atom at)
304 data = get_prop_data(win, at, XA_CARDINAL, 0);
312 int find_desktop(Window win)
314 return generic_get_int(win, atoms[_NET_WM_DESKTOP]);
317 int find_state(Window win, atom_t atom)
323 data = get_prop_data(win, atoms[_NET_WM_STATE], XA_ATOM, &num);
326 if ((data[num]) == atoms[atom])
334 /* this naming is very confusing :) */
335 int is_hidden(Window win)
337 return find_state(win, _NET_WM_STATE_SKIP_TASKBAR);
340 int is_iconified(Window win)
342 return find_state(win, _NET_WM_STATE_HIDDEN);
345 int is_shaded(Window win)
347 return find_state(win, _NET_WM_STATE_SHADED);
350 int get_current_desktop(void)
352 return generic_get_int(root_win, atoms[_NET_CURRENT_DESKTOP]);
355 int get_number_of_desktops(void)
357 return generic_get_int(root_win, atoms[_NET_NUMBER_OF_DESKTOPS]);
360 void add_task(Window win, int focus)
368 /* is this window on a different desktop? */
369 desk = find_desktop(win);
370 if ((desk != 0xffffffff && tb.my_desktop != desk) || is_hidden(win))
373 tk = calloc(1, sizeof(task));
376 tk->name = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
377 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
378 // tk->name = get_prop_data(win, XA_WM_NAME, XA_STRING, 0);
379 //tk->locale = get_prop_data(win, XA_WM_LOCALE_NAME, XA_STRING, 0);
380 tk->iconified = is_iconified(win);
381 tk->shaded = is_shaded(win);
383 get_task_kdeicon(tk);
384 if (tk->icon == None)
385 get_task_hinticon(tk);
387 XSelectInput(dd, win, PropertyChangeMask | FocusChangeMask
388 | StructureNotifyMask);
390 /* now append it to our linked list */
407 void set_prop(Window win, Atom at, Atom type, long val)
409 XChangeProperty(dd, win, at, type, 32,
410 PropModeReplace, (unsigned char *)&val, 1);
413 Window gui_create_taskbar(void)
417 XSizeHints size_hints;
419 XSetWindowAttributes att;
422 att.background_pixel = palette[0];
423 att.event_mask = ButtonPressMask | ExposureMask;
425 win = rspanelwin = XCreateWindow(/* display */ dd,
426 /* parent */ root_win,
428 /* y */ scr_height - WINHEIGHT,
429 /* XXX Maybe just use scr_width here? */
430 /* width */ WINWIDTH,
431 /* height */ WINHEIGHT,
433 /* depth */ CopyFromParent,
434 /* class */ InputOutput,
435 /* visual */ CopyFromParent,
436 /*value mask*/ CWBackPixel | CWEventMask,
439 /* reside on ALL desktops */
440 set_prop(win, atoms[_NET_WM_DESKTOP], XA_CARDINAL, 0xFFFFFFFF);
441 set_prop(win, atoms[_NET_WM_WINDOW_TYPE], XA_ATOM,
442 atoms[_NET_WM_WINDOW_TYPE_DOCK]);
443 set_prop(win, atoms[_NET_WM_STATE], XA_ATOM, atoms[_NET_WM_STATE_BELOW]);
444 /* use old gnome hint since sawfish doesn't support _NET_WM_STRUT */
445 set_prop(win, atoms[_WIN_HINTS], XA_CARDINAL,
446 WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST |
447 WIN_HINTS_SKIP_TASKBAR | WIN_HINTS_DO_NOT_COVER);
448 XChangeProperty(dd, win, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
449 (unsigned char *)"rspanel", 7);
451 /* borderless motif hint */
452 bzero(&mwm, sizeof(mwm));
453 mwm.flags = MWM_HINTS_DECORATIONS;
454 XChangeProperty(dd, win, atoms[_MOTIF_WM_HINTS], atoms[_MOTIF_WM_HINTS], 32,
455 PropModeReplace, (unsigned char *)&mwm,
456 sizeof(MWMHints) / 4);
458 /* make sure the WM obays our window position */
459 size_hints.flags = PPosition;
460 /*XSetWMNormalHints (dd, win, &size_hints); */
461 XChangeProperty(dd, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
462 PropModeReplace, (unsigned char *)&size_hints,
463 sizeof(XSizeHints) / 4);
465 /* make our window unfocusable */
466 wmhints.flags = InputHint;
467 wmhints.input = False;
468 /*XSetWMHints (dd, win, &wmhints); */
469 XChangeProperty(dd, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace,
470 (unsigned char *)&wmhints, sizeof(XWMHints) / 4);
472 xclhints.res_name = "rspanel";
473 xclhints.res_class = "RSPanel";
474 XSetClassHint(dd, win, &xclhints);
479 xftdraw = XftDrawCreate(dd, win, DefaultVisual(dd, scr_screen),
480 DefaultColormap(dd, scr_screen));
498 PangoContext *context;
499 PangoFontDescription *pfd;
504 xcl.red = cols[i].red;
505 xcl.green = cols[i].green;
506 xcl.blue = cols[i].blue;
507 XAllocColor(dd, DefaultColormap(dd, scr_screen), &xcl);
508 palette[i] = xcl.pixel;
510 } while (i < PALETTE_COUNT);
514 xfs = XftFontOpenName(dd, scr_screen, XFT_FONT);
516 fontname = FONT_NAME;
518 xfs = XLoadQueryFont(dd, fontname);
523 gcv.graphics_exposures = False;
526 text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2);
527 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
529 text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2);
531 fore_gc = XCreateGC(dd, root_win, GCFont | GCGraphicsExposures, &gcv);
534 pfd = pango_font_description_new();
535 pango_font_description_set_absolute_size(pfd, PANGO_FONT_SIZE*PANGO_SCALE);
536 pango_font_description_set_family(pfd, PANGO_FONT_PREF);
537 context = pango_xft_get_context(dd, root_win);
538 pango_context_set_font_description(context, pfd);
539 pl = pango_layout_new(context);
541 pango_layout_set_single_paragraph_mode(pl, TRUE);
542 pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_END);
544 text_y = (WINHEIGHT*PANGO_SCALE-7*PANGO_SCALE);
545 pango_font_description_free(pfd);
546 g_object_unref(context);
548 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
552 XpmCreatePixmapFromData(dd, root_win, icon_xpm, &generic_icon,
553 &generic_mask, NULL);
558 inst = RrInstanceNew(dd, scr_screen);
559 theme = RrThemeNew(inst, "Mikachu", TRUE, NULL, NULL, NULL, NULL, NULL);
563 void gui_draw_vline(int x)
566 draw_line(x, 0, x, WINHEIGHT);
568 draw_line(x + 1, 0, x + 1, WINHEIGHT);
571 void draw_box(int x, int width)
573 set_foreground(1); /* mid gray */
574 fill_rect(x + 3, 2, width - 2, WINHEIGHT - 4);
576 set_foreground(3); /* white */
577 draw_line(x + 3, WINHEIGHT - 2, x + width - 1, WINHEIGHT - 2);
578 draw_line(x + width - 1, 1, x + width - 1, WINHEIGHT - 2);
580 set_foreground(4); /* darkest gray */
581 draw_line(x + 3, 1, x + width - 1, 1);
582 draw_line(x + 3, 2, x + 3, WINHEIGHT - 3);
587 void gui_draw_task(task *tk)
589 RrAppearance *a = tk->focused ? theme->a_focused_label : theme->a_unfocused_label;
590 RrAppearance *b = tk->focused ? theme->a_focused_title : theme->a_unfocused_title;
591 a->surface.parent = b;
592 a->surface.parentx = PADDING;
593 a->texture[0].data.text.string = tk->name;
594 RrPaintPixmap(b, tk->width, WINHEIGHT);
595 RrPaintPixmap(a, tk->width-2*PADDING, WINHEIGHT);
597 XCopyArea(dd, a->pixmap, b->pixmap, RrColorGC(b->surface.primary), 0, 0, tk->width-2*PADDING, WINHEIGHT, PADDING, 0);
598 XCopyArea(dd, b->pixmap, tb.win, RrColorGC(b->surface.primary), 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
600 XCopyArea(dd, a->pixmap, tb.win, RrColorGC(b->surface.primary), 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
603 XFreePixmap(dd, a->pixmap);
604 XFreePixmap(dd, b->pixmap);
607 void gui_draw_task(task * tk)
610 int taskw = tk->width;
624 set_foreground(0); /* mid gray */
625 fill_rect(x + 2, 0, taskw - 1, WINHEIGHT);
629 int text_x = x + TEXTPAD + TEXTPAD + (tk->icon ? ICONWIDTH : -1*ICONWIDTH/4);
630 #define SETCOL(x) col.color.red = cols[x].red;\
631 col.color.green = cols[x].green;\
632 col.color.blue = cols[x].blue;
635 pango_layout_set_width(pl, /*-1);*/(taskw - text_x + x) * PANGO_SCALE);
636 pango_layout_set_text(pl, tk->name, -1);
637 col.color.alpha = 0xffff;
641 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x+2)*PANGO_SCALE, text_y + 2);
643 } else if (tk->shaded) {
645 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x-2)*PANGO_SCALE, text_y - 2);
650 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), text_x*PANGO_SCALE, text_y);
654 /* check how many chars can fit */
655 len = strlen(tk->name);
657 XftTextExtentsUtf8(dd, xfs, tk->name, len, &ext);
658 if (ext.width < taskw - (text_x - x) - 2 || len <= 0)
663 col.color.alpha = 0xffff;
666 /* draw task's name dark (iconified) */
668 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y + 1, tk->name,
671 } else if (tk->shaded) {
672 /* draw task's name dark (shaded) */
674 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y - 1, tk->name,
682 /* draw task's name here */
683 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y, tk->name, len);
686 /* check how many chars can fit */
687 len = strlen(tk->name);
689 while (XTextWidth(xfs, tk->name, len) >= taskw - (text_x - x) - 2
694 /* draw task's name dark (iconified) */
696 XDrawString(dd, tb.win, fore_gc, text_x, text_y + 1, tk->name,
699 } else if (tk->shaded) {
700 /* draw task's name dark (shaded) */
702 XDrawString(dd, tb.win, fore_gc, text_x, text_y - 1, tk->name,
709 /* draw task's name here */
710 XDrawString(dd, tb.win, fore_gc, text_x, text_y, tk->name, len);
719 /* draw the task's icon */
720 XSetClipMask(dd, fore_gc, tk->mask);
721 XSetClipOrigin(dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
722 XCopyArea(dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT,
723 x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
724 XSetClipMask(dd, fore_gc, None);
728 void draw_dot(int x, int y)
731 XDrawPoint(dd, tb.win, fore_gc, x, y);
733 XDrawPoint(dd, tb.win, fore_gc, x + 1, y + 1);
736 void draw_grill(int x)
739 while (y < WINHEIGHT - 4) {
746 #ifdef MIKACHU //this only works in mikabox
747 void ob_action(Window win, char *action)
749 XClientMessageEvent xev;
750 char act_name[14+strlen(action)];
751 sprintf(act_name, "_OB_WM_ACTION_%s", action);
753 xev.type = ClientMessage;
755 xev.message_type = atoms[_OB_WM_ACTION];
757 /*strncpy(xev.data.b, action, 20);*/
758 xev.data.l[0] = XInternAtom(dd, act_name, False);
759 XSendEvent(dd, root_win, False, SubstructureRedirectMask, (XEvent *)&xev);
762 void netwm_action(Window win, atom_t atom, Time time, long l)
764 XClientMessageEvent xev = {
765 .type = ClientMessage,
769 .message_type = atoms[atom]
772 if (atom == _NET_ACTIVE_WINDOW) {
774 xev.data.l[1] = time;
776 } else if (atom == _NET_CURRENT_DESKTOP) {
778 xev.data.l[1] = time;
779 } else if (atom == _NET_RESTACK_WINDOW) {
783 xev.message_type = atoms[_NET_WM_STATE];
785 xev.data.l[1] = atoms[atom];
789 XSendEvent(dd, root_win, False, SubstructureNotifyMask
790 |SubstructureRedirectMask, (XEvent *)&xev);
795 void switch_desk(int new_desk, Time time)
797 if (get_number_of_desktops() <= new_desk)
800 netwm_action(None, _NET_CURRENT_DESKTOP, time, new_desk);
803 /* This doesn't work with pango yet */
804 void pager_draw_button(int x, int num)
811 if (num == tb.my_desktop) {
812 /* current desktop */
813 draw_box(x, PAGER_BUTTON_WIDTH);
816 fill_rect(x, 1, PAGER_BUTTON_WIDTH + 1, WINHEIGHT - 2);
822 col.color.alpha = 0xffff;
823 col.color.red = cols[5].red;
824 col.color.green = cols[5].green;
825 col.color.blue = cols[5].blue;
826 XftDrawString8(xftdraw, &col, xfs,
827 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y,
831 XDrawString(dd, tb.win, fore_gc,
832 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1,
837 void pager_draw(void)
839 int desks, i, x = GRILL_WIDTH;
841 desks = get_number_of_desktops();
843 for (i = 0; i < desks; i++) {
844 pager_draw_button(x, i);
847 x += PAGER_BUTTON_WIDTH;
855 void gui_draw_taskbar(void)
863 pager_size = TEXTPAD;
866 width = WINWIDTH - (pager_size + GRILL_WIDTH + GRILL_WIDTH);
869 if (tb.num_tasks == 0)
872 taskw = width / tb.num_tasks;
873 if (taskw > MAX_TASK_WIDTH)
874 taskw = MAX_TASK_WIDTH;
879 tk->width = taskw - 1;
885 if (x < (width + pager_size + 2)) {
889 fill_rect(x + 2, 0, WINWIDTH, WINHEIGHT);
893 gui_draw_vline(WINWIDTH - 8);
896 draw_grill(WINWIDTH - 6);
899 task *find_task(Window win)
901 task *list = tb.task_list;
903 if (list->win == win)
910 void del_task(Window win)
912 task *next, *prev = 0, *list = tb.task_list;
916 if (list->win == win) {
917 /* unlink and free this task */
919 if (list->icon_copied) {
920 XFreePixmap(dd, list->icon);
921 if (list->mask != None)
922 XFreePixmap(dd, list->mask);
938 void move_taskbar(void)
945 x = TEXTPAD - WINWIDTH;
948 y = scr_height - WINHEIGHT;
950 XMoveWindow(dd, tb.win, x, y);
953 void taskbar_read_clientlist(void)
955 Window *win, focus_win = 0;
956 int num, i, desk, new_desk = 0;
958 desk = get_current_desktop();
965 XResizeWindow(dd, rspanelwin, WINWIDTH, WINHEIGHT);
968 if (desk != tb.my_desktop) {
970 tb.my_desktop = desk;
973 win = get_prop_data(root_win, atoms[_NET_ACTIVE_WINDOW], XA_WINDOW, &num);
977 win = get_prop_data(root_win, atoms[_NET_CLIENT_LIST], XA_WINDOW, &num);
981 /* remove windows that arn't in the _NET_CLIENT_LIST anymore */
984 list->focused = (focus_win == list->win);
988 for (i = num - 1; i >= 0; i--)
989 if (list->win == win[i] && !is_hidden(win[i]))
997 /* add any new windows */
998 for (i = 0; i < num; i++) {
999 if (!find_task(win[i]))
1000 add_task(win[i], (win[i] == focus_win));
1006 void handle_press(int x, int y, int button, Time time)
1011 if ((y > 2 && y < WINHEIGHT - 2 && x > GRILL_WIDTH) && button == 1)
1012 switch_desk((x - GRILL_WIDTH) / PAGER_BUTTON_WIDTH, time);
1015 /* clicked left grill */
1018 tb.at_top = 1 - tb.at_top;
1020 } else if (button == 4) {
1026 /* clicked right grill */
1027 else if (x + TEXTPAD > WINWIDTH) {
1028 if (tb.hidden && (button == 1 || button == 5)) {
1031 } else if (!tb.hidden && (button == 1 || button == 4)) {
1038 /* clicked on a task button */
1039 /* XXX Make this configureable */
1040 if (x > tk->pos_x && x < tk->pos_x + tk->width) {
1043 netwm_action(tk->win, _NET_ACTIVE_WINDOW, time, 0);
1047 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1049 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, ADD);
1052 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Opposite);
1055 if (is_shaded(tk->win))
1056 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1058 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, ADD);
1061 if (is_shaded(tk->win))
1062 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, REMOVE);
1064 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1068 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1069 #ifdef MIKACHU //this doesn't work for anyone else anyway
1071 ob_action(tk->win, "focus");
1075 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1078 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1084 } /* clicked on the background */
1087 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Above);
1090 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Below);
1093 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Opposite);
1107 void handle_focusin(Window win)
1114 if (tk->win != win) {
1119 if (tk->win == win) {
1128 void handle_propertynotify(Window win, Atom at)
1132 if (win == root_win) {
1133 if (at == atoms[_NET_CLIENT_LIST] || at == atoms[_NET_CURRENT_DESKTOP] || at == atoms[_NET_CLIENT_LIST_STACKING]) {
1134 taskbar_read_clientlist();
1140 /* XXX make this work when SKIP_TASKBAR is toggled too */
1141 tk = find_task(win);
1145 if (at == XA_WM_NAME || at == atoms[_NET_WM_NAME]) {
1146 /* window's title changed */
1148 newname = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
1149 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
1151 if (tk->name && !strcmp(newname, tk->name)) {
1160 } else if (at == atoms[_NET_WM_STATE]) {
1161 /* iconified state changed? */
1162 if (is_iconified(tk->win) != tk->iconified) {
1163 tk->iconified = !tk->iconified;
1166 /* shaded state changed? */
1167 if (is_shaded(tk->win) != tk->shaded) {
1168 tk->shaded = !tk->shaded;
1171 } else if (at == XA_WM_HINTS) {
1172 /* some windows set their WM_HINTS icon after mapping */
1173 //if (tk->icon == generic_icon) {
1174 get_task_hinticon(tk);
1177 } else if (at == atoms[_NET_WM_DESKTOP]) {
1178 if (find_desktop(win) != get_current_desktop())
1183 void handle_error(Display * d, XErrorEvent * ev)
1191 main(int argc, char *argv[])
1196 dd = XOpenDisplay(NULL);
1199 scr_screen = DefaultScreen(dd);
1200 scr_depth = DefaultDepth(dd, scr_screen);
1201 scr_height = DisplayHeight(dd, scr_screen);
1202 scr_width = DisplayWidth(dd, scr_screen);
1203 root_win = RootWindow(dd, scr_screen);
1205 /* helps us catch windows closing/opening */
1206 XSelectInput(dd, root_win, PropertyChangeMask);
1208 XSetErrorHandler((XErrorHandler) handle_error);
1210 XInternAtoms(dd, atom_names, ATOM_COUNT, False, atoms);
1213 memset(&tb, 0, sizeof(tb));
1214 tb.win = gui_create_taskbar();
1217 while (XNextEvent(dd, &ev) == Success) {
1220 handle_press(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.time);
1223 del_task(ev.xdestroywindow.window);
1228 case PropertyNotify:
1229 handle_propertynotify(ev.xproperty.window, ev.xproperty.atom);
1232 if (ev.xfocus.mode != NotifyGrab)
1233 handle_focusin(ev.xfocus.window);
1236 printf ("unknown evt type: %d\n", ev.type); */
1239 /* RrThemeFree(theme);
1240 * RrInstanceFree(inst);
1241 * XCloseDisplay (dd);