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>
86 RrAppearance *background;
87 RrAppearance *focused_task;
88 RrAppearance *unfocused_task;
89 RrAppearance *normal_text;
90 RrAppearance *iconified_text;
105 unsigned short red, green, blue;
107 {0xd75c, 0xd75c, 0xe75c}, /* 0. light gray */
108 {0xbefb, 0xbaea, 0xcefb}, /* 1. mid gray */
109 {0xaefb, 0xaaea, 0xfefb}, /* 2. dark gray */
110 {0xefbe, 0xefbe, 0xffbe}, /* 3. white */
111 {0x8617, 0x8207, 0x9617}, /* 4. darkest gray */
112 {0x0000, 0x0000, 0x1000}, /* 5. black */
115 #define PALETTE_COUNT (sizeof (cols) / sizeof (cols[0].red) / 3)
117 unsigned long palette[PALETTE_COUNT];
119 char *atom_names[] = {
125 "_NET_WM_STATE_SKIP_TASKBAR",
126 "_NET_WM_STATE_SHADED",
127 "_NET_WM_STATE_BELOW",
128 "_NET_WM_STATE_HIDDEN",
130 "_NET_WM_WINDOW_TYPE",
131 "_NET_WM_WINDOW_TYPE_DOCK",
136 "_NET_CLIENT_LIST_STACKING",
137 "_NET_NUMBER_OF_DESKTOPS",
138 "_NET_CURRENT_DESKTOP",
142 "_NET_ACTIVE_WINDOW",
143 "_NET_RESTACK_WINDOW",
152 _NET_WM_STATE_SKIP_TASKBAR,
153 _NET_WM_STATE_SHADED,
155 _NET_WM_STATE_HIDDEN,
158 _NET_WM_WINDOW_TYPE_DOCK,
162 _NET_CLIENT_LIST_STACKING,
163 _NET_NUMBER_OF_DESKTOPS,
164 _NET_CURRENT_DESKTOP,
174 Atom atoms[ATOM_COUNT];
182 void *get_prop_data(Window win, Atom prop, Atom type, int *items)
186 unsigned long items_ret;
187 unsigned long after_ret;
188 unsigned char *prop_data;
192 XGetWindowProperty(dd, win, prop, 0, 0x7fffffff, False, type, &type_ret,
193 &format_ret, &items_ret, &after_ret, &prop_data);
200 void set_foreground(int index)
202 XSetForeground(dd, fore_gc, palette[index]);
205 void draw_line(int x, int y, int a, int b)
207 XDrawLine(dd, tb.win, fore_gc, x, y, a, b);
210 void fill_rect(int x, int y, int a, int b)
212 XFillRectangle(dd, tb.win, fore_gc, x, y, a, b);
215 void scale_icon(task * tk)
218 unsigned int w, h, d, bw;
219 Pixmap pix, mk = None;
223 XGetGeometry(dd, tk->icon, &pix, &x, &y, &w, &h, &bw, &d);
224 pix = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, scr_depth);
226 if (tk->mask != None) {
227 mk = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, 1);
228 gcv.subwindow_mode = IncludeInferiors;
229 gcv.graphics_exposures = False;
230 mgc = XCreateGC(dd, mk, GCGraphicsExposures | GCSubwindowMode, &gcv);
235 /* this is my simple & dirty scaling routine */
236 for (y = ICONHEIGHT - 1; y >= 0; y--) {
237 yy = (y * h) / ICONHEIGHT;
238 for (x = ICONWIDTH - 1; x >= 0; x--) {
239 xx = (x * w) / ICONWIDTH;
241 XCopyPlane(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y, 1);
243 XCopyArea(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y);
245 XCopyArea(dd, tk->mask, mk, mgc, xx, yy, 1, 1, x, y);
257 void get_task_hinticon(task * tk)
261 if (tk->icon != None && tk->icon != generic_icon)
262 if (tk->icon_copied) {
263 XFreePixmap(dd, tk->icon);
264 if (tk->mask != None && tk->mask != generic_mask)
265 XFreePixmap(dd, tk->mask);
271 hin = (XWMHints *)get_prop_data(tk->win, XA_WM_HINTS, XA_WM_HINTS, 0);
273 if ((hin->flags & IconPixmapHint)) {
274 if ((hin->flags & IconMaskHint)) {
275 tk->mask = hin->icon_mask;
278 tk->icon = hin->icon_pixmap;
285 if (tk->icon == None) {
286 tk->icon = generic_icon;
287 if (tk->mask != None)
288 XFreePixmap(dd, tk->mask);
289 tk->mask = generic_mask;
293 void get_task_kdeicon(task * tk)
297 data = get_prop_data(tk->win, atoms[KWM_WIN_ICON], atoms[KWM_WIN_ICON], 0);
305 int generic_get_int(Window win, Atom at)
310 data = get_prop_data(win, at, XA_CARDINAL, 0);
318 int find_desktop(Window win)
320 return generic_get_int(win, atoms[_NET_WM_DESKTOP]);
323 int find_state(Window win, atom_t atom)
329 data = get_prop_data(win, atoms[_NET_WM_STATE], XA_ATOM, &num);
332 if ((data[num]) == atoms[atom])
340 /* this naming is very confusing :) */
341 int is_hidden(Window win)
343 return find_state(win, _NET_WM_STATE_SKIP_TASKBAR);
346 int is_iconified(Window win)
348 return find_state(win, _NET_WM_STATE_HIDDEN);
351 int is_shaded(Window win)
353 return find_state(win, _NET_WM_STATE_SHADED);
356 int get_current_desktop(void)
358 return generic_get_int(root_win, atoms[_NET_CURRENT_DESKTOP]);
361 int get_number_of_desktops(void)
363 return generic_get_int(root_win, atoms[_NET_NUMBER_OF_DESKTOPS]);
366 void add_task(Window win, int focus)
374 /* is this window on a different desktop? */
375 desk = find_desktop(win);
376 if ((desk != 0xffffffff && tb.my_desktop != desk) || is_hidden(win))
379 tk = calloc(1, sizeof(task));
382 tk->name = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
383 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
384 // tk->name = get_prop_data(win, XA_WM_NAME, XA_STRING, 0);
385 //tk->locale = get_prop_data(win, XA_WM_LOCALE_NAME, XA_STRING, 0);
386 tk->iconified = is_iconified(win);
387 tk->shaded = is_shaded(win);
389 get_task_kdeicon(tk);
390 if (tk->icon == None)
391 get_task_hinticon(tk);
393 XSelectInput(dd, win, PropertyChangeMask | FocusChangeMask
394 | StructureNotifyMask);
396 /* now append it to our linked list */
413 void set_prop(Window win, Atom at, Atom type, long val)
415 XChangeProperty(dd, win, at, type, 32,
416 PropModeReplace, (unsigned char *)&val, 1);
419 Window gui_create_taskbar(void)
423 XSizeHints size_hints;
425 XSetWindowAttributes att;
428 att.background_pixel = palette[0];
429 att.event_mask = ButtonPressMask | ExposureMask;
431 win = rspanelwin = XCreateWindow(/* display */ dd,
432 /* parent */ root_win,
434 /* y */ scr_height - WINHEIGHT,
435 /* XXX Maybe just use scr_width here? */
436 /* width */ WINWIDTH,
437 /* height */ WINHEIGHT,
439 /* depth */ CopyFromParent,
440 /* class */ InputOutput,
441 /* visual */ CopyFromParent,
442 /*value mask*/ CWBackPixel | CWEventMask,
445 /* reside on ALL desktops */
446 set_prop(win, atoms[_NET_WM_DESKTOP], XA_CARDINAL, 0xFFFFFFFF);
447 set_prop(win, atoms[_NET_WM_WINDOW_TYPE], XA_ATOM,
448 atoms[_NET_WM_WINDOW_TYPE_DOCK]);
449 set_prop(win, atoms[_NET_WM_STATE], XA_ATOM, atoms[_NET_WM_STATE_BELOW]);
450 /* use old gnome hint since sawfish doesn't support _NET_WM_STRUT */
451 set_prop(win, atoms[_WIN_HINTS], XA_CARDINAL,
452 WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST |
453 WIN_HINTS_SKIP_TASKBAR | WIN_HINTS_DO_NOT_COVER);
454 XChangeProperty(dd, win, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
455 (unsigned char *)"rspanel", 7);
457 /* borderless motif hint */
458 bzero(&mwm, sizeof(mwm));
459 mwm.flags = MWM_HINTS_DECORATIONS;
460 XChangeProperty(dd, win, atoms[_MOTIF_WM_HINTS], atoms[_MOTIF_WM_HINTS], 32,
461 PropModeReplace, (unsigned char *)&mwm,
462 sizeof(MWMHints) / 4);
464 /* make sure the WM obays our window position */
465 size_hints.flags = PPosition;
466 /*XSetWMNormalHints (dd, win, &size_hints); */
467 XChangeProperty(dd, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
468 PropModeReplace, (unsigned char *)&size_hints,
469 sizeof(XSizeHints) / 4);
471 /* make our window unfocusable */
472 wmhints.flags = InputHint;
473 wmhints.input = False;
474 /*XSetWMHints (dd, win, &wmhints); */
475 XChangeProperty(dd, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace,
476 (unsigned char *)&wmhints, sizeof(XWMHints) / 4);
478 xclhints.res_name = "rspanel";
479 xclhints.res_class = "RSPanel";
480 XSetClassHint(dd, win, &xclhints);
485 xftdraw = XftDrawCreate(dd, win, DefaultVisual(dd, scr_screen),
486 DefaultColormap(dd, scr_screen));
495 static void set_default_appearance(RrAppearance *a)
497 a->surface.grad = RR_SURFACE_SOLID;
498 a->surface.relief = RR_RELIEF_FLAT;
499 a->surface.bevel = RR_BEVEL_1;
500 a->surface.interlaced = FALSE;
501 a->surface.border = FALSE;
502 a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
503 a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
515 PangoContext *context;
516 PangoFontDescription *pfd;
521 xcl.red = cols[i].red;
522 xcl.green = cols[i].green;
523 xcl.blue = cols[i].blue;
524 XAllocColor(dd, DefaultColormap(dd, scr_screen), &xcl);
525 palette[i] = xcl.pixel;
527 } while (i < PALETTE_COUNT);
531 xfs = XftFontOpenName(dd, scr_screen, XFT_FONT);
533 fontname = FONT_NAME;
535 xfs = XLoadQueryFont(dd, fontname);
540 gcv.graphics_exposures = False;
543 text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2);
544 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
546 text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2);
548 fore_gc = XCreateGC(dd, root_win, GCFont | GCGraphicsExposures, &gcv);
551 pfd = pango_font_description_new();
552 pango_font_description_set_absolute_size(pfd, PANGO_FONT_SIZE*PANGO_SCALE);
553 pango_font_description_set_family(pfd, PANGO_FONT_PREF);
554 context = pango_xft_get_context(dd, root_win);
555 pango_context_set_font_description(context, pfd);
556 pl = pango_layout_new(context);
558 pango_layout_set_single_paragraph_mode(pl, TRUE);
559 pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_END);
561 text_y = (WINHEIGHT*PANGO_SCALE-7*PANGO_SCALE);
562 pango_font_description_free(pfd);
563 g_object_unref(context);
565 fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv);
569 XpmCreatePixmapFromData(dd, root_win, icon_xpm, &generic_icon,
570 &generic_mask, NULL);
575 inst = RrInstanceNew(dd, scr_screen);
576 set_default_appearance(background = RrAppearanceNew(inst, 0));
577 set_default_appearance(focused_task = RrAppearanceNew(inst, 0));
578 set_default_appearance(unfocused_task = RrAppearanceNew(inst, 0));
579 set_default_appearance(normal_text = RrAppearanceNew(inst, 1));
580 background->surface.grad = RR_SURFACE_SPLIT_VERTICAL;
581 background->surface.secondary = RrColorNew(inst, 90, 0, 150);
582 background->surface.primary = RrColorNew(inst, 90, 80, 150);
583 unfocused_task->surface.parent = background;
584 unfocused_task->surface.grad = RR_SURFACE_PARENTREL;
585 focused_task->surface.parent = background;
586 focused_task->surface.grad = RR_SURFACE_CROSS_DIAGONAL;
587 focused_task->surface.secondary = RrColorNew(inst, 50, 60, 110);
588 focused_task->surface.primary = RrColorNew(inst, 90, 120, 250);
589 normal_text->surface.grad = RR_SURFACE_PARENTREL;
590 normal_text->texture[0].type = RR_TEXTURE_TEXT;
591 normal_text->texture[0].data.text.font = RrFontOpenDefault(inst);
592 normal_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
593 iconified_text = RrAppearanceCopy(normal_text);
594 normal_text->texture[0].data.text.color = RrColorNew(inst, 200, 200, 200);
595 iconified_text->texture[0].data.text.color = RrColorNew(inst, 0, 150, 0);
599 void gui_draw_vline(int x)
602 draw_line(x, 0, x, WINHEIGHT);
604 draw_line(x + 1, 0, x + 1, WINHEIGHT);
607 void draw_box(int x, int width)
609 set_foreground(1); /* mid gray */
610 fill_rect(x + 3, 2, width - 2, WINHEIGHT - 4);
612 set_foreground(3); /* white */
613 draw_line(x + 3, WINHEIGHT - 2, x + width - 1, WINHEIGHT - 2);
614 draw_line(x + width - 1, 1, x + width - 1, WINHEIGHT - 2);
616 set_foreground(4); /* darkest gray */
617 draw_line(x + 3, 1, x + width - 1, 1);
618 draw_line(x + 3, 2, x + 3, WINHEIGHT - 3);
623 void gui_draw_task(task *tk)
625 RrAppearance *a = (tk->iconified || tk->shaded) ? iconified_text : normal_text;
626 RrAppearance *b = tk->focused ? focused_task : unfocused_task;
627 a->surface.parent = b;
628 a->surface.parentx = PADDING;
629 a->texture[0].data.text.string = tk->name;
630 b->surface.parentx = tk->pos_x;
631 RrPaintPixmap(b, tk->width, WINHEIGHT);
632 RrPaintPixmap(a, tk->width-2*PADDING, WINHEIGHT);
634 XCopyArea(dd, a->pixmap, b->pixmap, fore_gc, 0, 0, tk->width-2*PADDING, WINHEIGHT, PADDING, 0);
635 XCopyArea(dd, b->pixmap, tb.win, fore_gc, 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
637 XCopyArea(dd, a->pixmap, tb.win, fore_gc, 0, 0, tk->width, WINHEIGHT, tk->pos_x, 0);
640 XFreePixmap(dd, a->pixmap);
641 XFreePixmap(dd, b->pixmap);
644 void gui_draw_task(task * tk)
647 int taskw = tk->width;
661 set_foreground(0); /* mid gray */
662 fill_rect(x + 2, 0, taskw - 1, WINHEIGHT);
666 int text_x = x + TEXTPAD + TEXTPAD + (tk->icon ? ICONWIDTH : -1*ICONWIDTH/4);
667 #define SETCOL(x) col.color.red = cols[x].red;\
668 col.color.green = cols[x].green;\
669 col.color.blue = cols[x].blue;
672 pango_layout_set_width(pl, /*-1);*/(taskw - text_x + x) * PANGO_SCALE);
673 pango_layout_set_text(pl, tk->name, -1);
674 col.color.alpha = 0xffff;
678 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x+2)*PANGO_SCALE, text_y + 2);
680 } else if (tk->shaded) {
682 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x-2)*PANGO_SCALE, text_y - 2);
687 pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), text_x*PANGO_SCALE, text_y);
691 /* check how many chars can fit */
692 len = strlen(tk->name);
694 XftTextExtentsUtf8(dd, xfs, tk->name, len, &ext);
695 if (ext.width < taskw - (text_x - x) - 2 || len <= 0)
700 col.color.alpha = 0xffff;
703 /* draw task's name dark (iconified) */
705 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y + 1, tk->name,
708 } else if (tk->shaded) {
709 /* draw task's name dark (shaded) */
711 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y - 1, tk->name,
719 /* draw task's name here */
720 XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y, tk->name, len);
723 /* check how many chars can fit */
724 len = strlen(tk->name);
726 while (XTextWidth(xfs, tk->name, len) >= taskw - (text_x - x) - 2
731 /* draw task's name dark (iconified) */
733 XDrawString(dd, tb.win, fore_gc, text_x, text_y + 1, tk->name,
736 } else if (tk->shaded) {
737 /* draw task's name dark (shaded) */
739 XDrawString(dd, tb.win, fore_gc, text_x, text_y - 1, tk->name,
746 /* draw task's name here */
747 XDrawString(dd, tb.win, fore_gc, text_x, text_y, tk->name, len);
756 /* draw the task's icon */
757 XSetClipMask(dd, fore_gc, tk->mask);
758 XSetClipOrigin(dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
759 XCopyArea(dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT,
760 x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2);
761 XSetClipMask(dd, fore_gc, None);
765 void draw_dot(int x, int y)
768 XDrawPoint(dd, tb.win, fore_gc, x, y);
770 XDrawPoint(dd, tb.win, fore_gc, x + 1, y + 1);
773 void draw_grill(int x)
776 while (y < WINHEIGHT - 4) {
783 void netwm_action(Window win, atom_t atom, Time time, long l)
785 XClientMessageEvent xev = {
786 .type = ClientMessage,
790 .message_type = atoms[atom]
793 if (atom == _NET_ACTIVE_WINDOW) {
795 xev.data.l[1] = time;
797 } else if (atom == _NET_CURRENT_DESKTOP) {
799 xev.data.l[1] = time;
800 } else if (atom == _NET_RESTACK_WINDOW) {
803 } else if (atom == _OB_FOCUS) {
805 xev.message_type = atoms[_NET_WM_STATE];
807 xev.data.l[1] = atoms[atom];
811 XSendEvent(dd, root_win, False, SubstructureNotifyMask
812 |SubstructureRedirectMask, (XEvent *)&xev);
817 void switch_desk(int new_desk, Time time)
819 if (get_number_of_desktops() <= new_desk)
822 netwm_action(None, _NET_CURRENT_DESKTOP, time, new_desk);
825 /* This doesn't work with pango yet */
826 void pager_draw_button(int x, int num)
833 if (num == tb.my_desktop) {
834 /* current desktop */
835 draw_box(x, PAGER_BUTTON_WIDTH);
838 fill_rect(x, 1, PAGER_BUTTON_WIDTH + 1, WINHEIGHT - 2);
844 col.color.alpha = 0xffff;
845 col.color.red = cols[5].red;
846 col.color.green = cols[5].green;
847 col.color.blue = cols[5].blue;
848 XftDrawString8(xftdraw, &col, xfs,
849 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2), text_y,
853 XDrawString(dd, tb.win, fore_gc,
854 x + ((PAGER_BUTTON_WIDTH - PAGER_DIGIT_WIDTH) / 2) - 1,
859 void pager_draw(void)
861 int desks, i, x = GRILL_WIDTH;
863 desks = get_number_of_desktops();
865 for (i = 0; i < desks; i++) {
866 pager_draw_button(x, i);
869 x += PAGER_BUTTON_WIDTH;
877 void gui_draw_taskbar(void)
885 pager_size = TEXTPAD;
889 width = WINWIDTH - (pager_size + GRILL_WIDTH);
891 #warning only rerender if width changed!
892 RrPaintPixmap(background, width, WINHEIGHT);
893 XCopyArea(dd, background->pixmap, tb.win, fore_gc, 0, 0, width, WINHEIGHT, x, 0);
895 if (tb.num_tasks == 0)
898 taskw = width / tb.num_tasks;
899 if (taskw > MAX_TASK_WIDTH)
900 taskw = MAX_TASK_WIDTH;
905 tk->width = taskw - 1;
911 if (x < (width + pager_size + 2)) {
915 fill_rect(x + 2, 0, WINWIDTH, WINHEIGHT);
919 gui_draw_vline(WINWIDTH - 8);
922 draw_grill(WINWIDTH - 6);
925 task *find_task(Window win)
927 task *list = tb.task_list;
929 if (list->win == win)
936 void del_task(Window win)
938 task *next, *prev = 0, *list = tb.task_list;
942 if (list->win == win) {
943 /* unlink and free this task */
945 if (list->icon_copied) {
946 XFreePixmap(dd, list->icon);
947 if (list->mask != None)
948 XFreePixmap(dd, list->mask);
964 void move_taskbar(void)
971 x = TEXTPAD - WINWIDTH;
974 y = scr_height - WINHEIGHT;
976 XMoveWindow(dd, tb.win, x, y);
979 void taskbar_read_clientlist(void)
981 Window *win, focus_win = 0;
982 int num, i, desk, new_desk = 0;
984 desk = get_current_desktop();
991 XResizeWindow(dd, rspanelwin, WINWIDTH, WINHEIGHT);
994 if (desk != tb.my_desktop) {
996 tb.my_desktop = desk;
999 win = get_prop_data(root_win, atoms[_NET_ACTIVE_WINDOW], XA_WINDOW, &num);
1003 win = get_prop_data(root_win, atoms[_NET_CLIENT_LIST], XA_WINDOW, &num);
1007 /* remove windows that arn't in the _NET_CLIENT_LIST anymore */
1008 list = tb.task_list;
1010 list->focused = (focus_win == list->win);
1014 for (i = num - 1; i >= 0; i--)
1015 if (list->win == win[i] && !is_hidden(win[i]))
1017 del_task(list->win);
1023 /* add any new windows */
1024 for (i = 0; i < num; i++) {
1025 if (!find_task(win[i]))
1026 add_task(win[i], (win[i] == focus_win));
1032 void handle_press(int x, int y, int button, Time time)
1037 if ((y > 2 && y < WINHEIGHT - 2 && x > GRILL_WIDTH) && button == 1)
1038 switch_desk((x - GRILL_WIDTH) / PAGER_BUTTON_WIDTH, time);
1041 /* clicked left grill */
1044 tb.at_top = 1 - tb.at_top;
1046 } else if (button == 4) {
1052 /* clicked right grill */
1053 else if (x + TEXTPAD > WINWIDTH) {
1054 if (tb.hidden && (button == 1 || button == 5)) {
1057 } else if (!tb.hidden && (button == 1 || button == 4)) {
1064 /* clicked on a task button */
1065 /* XXX Make this configureable */
1066 if (x > tk->pos_x && x < tk->pos_x + tk->width) {
1069 netwm_action(tk->win, _NET_ACTIVE_WINDOW, time, 0);
1073 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1075 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, ADD);
1078 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Opposite);
1081 if (is_shaded(tk->win))
1082 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1084 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, ADD);
1087 if (is_shaded(tk->win))
1088 netwm_action(tk->win, _NET_WM_STATE_SHADED, time, REMOVE);
1090 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1094 netwm_action(tk->win, _NET_WM_STATE_HIDDEN, time, REMOVE);
1096 netwm_action(tk->win, _OB_FOCUS, 0, 0);
1099 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Below);
1102 netwm_action(tk->win, _NET_RESTACK_WINDOW, time, Above);
1108 } /* clicked on the background */
1111 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Above);
1114 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Below);
1117 netwm_action(tb.win, _NET_RESTACK_WINDOW, time, Opposite);
1131 void handle_focusin(Window win)
1138 if (tk->win != win) {
1143 if (tk->win == win) {
1152 void handle_propertynotify(Window win, Atom at)
1156 if (win == root_win) {
1157 if (at == atoms[_NET_CLIENT_LIST] || at == atoms[_NET_CURRENT_DESKTOP] || at == atoms[_NET_CLIENT_LIST_STACKING]) {
1158 taskbar_read_clientlist();
1164 /* XXX make this work when SKIP_TASKBAR is toggled too */
1165 tk = find_task(win);
1169 if (at == XA_WM_NAME || at == atoms[_NET_WM_NAME]) {
1170 /* window's title changed */
1172 newname = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?:
1173 get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0);
1175 if (tk->name && !strcmp(newname, tk->name)) {
1184 } else if (at == atoms[_NET_WM_STATE]) {
1185 /* iconified state changed? */
1186 if (is_iconified(tk->win) != tk->iconified) {
1187 tk->iconified = !tk->iconified;
1190 /* shaded state changed? */
1191 if (is_shaded(tk->win) != tk->shaded) {
1192 tk->shaded = !tk->shaded;
1195 } else if (at == XA_WM_HINTS) {
1196 /* some windows set their WM_HINTS icon after mapping */
1197 //if (tk->icon == generic_icon) {
1198 get_task_hinticon(tk);
1201 } else if (at == atoms[_NET_WM_DESKTOP]) {
1202 if (find_desktop(win) != get_current_desktop())
1207 void handle_error(Display * d, XErrorEvent * ev)
1215 main(int argc, char *argv[])
1220 dd = XOpenDisplay(NULL);
1223 scr_screen = DefaultScreen(dd);
1224 scr_depth = DefaultDepth(dd, scr_screen);
1225 scr_height = DisplayHeight(dd, scr_screen);
1226 scr_width = DisplayWidth(dd, scr_screen);
1227 root_win = RootWindow(dd, scr_screen);
1229 /* helps us catch windows closing/opening */
1230 XSelectInput(dd, root_win, PropertyChangeMask);
1232 XSetErrorHandler((XErrorHandler) handle_error);
1234 XInternAtoms(dd, atom_names, ATOM_COUNT, False, atoms);
1237 memset(&tb, 0, sizeof(tb));
1238 tb.win = gui_create_taskbar();
1241 while (XNextEvent(dd, &ev) == Success) {
1244 handle_press(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.time);
1247 del_task(ev.xdestroywindow.window);
1252 case PropertyNotify:
1253 handle_propertynotify(ev.xproperty.window, ev.xproperty.atom);
1256 if (ev.xfocus.mode != NotifyGrab)
1257 handle_focusin(ev.xfocus.window);
1260 printf ("unknown evt type: %d\n", ev.type); */
1263 /* RrThemeFree(theme);
1264 * RrInstanceFree(inst);
1265 * XCloseDisplay (dd);