27 if (xkey->keycode == XKeysymToKeycode(dpy,XK_Tab))
28 return (xkey->state == ShiftMask) ? 1 : 2;
29 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Up))
31 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Right))
33 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Down))
35 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Left))
37 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Home))
39 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Insert))
41 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_End))
43 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_Return))
45 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_BackSpace))
48 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Subtract))
50 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Add))
52 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Up))
54 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Right))
56 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Down))
58 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Left))
60 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Home))
62 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Insert))
64 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_End))
66 else if (xkey->keycode == XKeysymToKeycode(dpy,XK_KP_Enter))
73 if (count == 0 && main->
run ==
true) {
98 cairo_surface_destroy(w->
image);
99 cairo_destroy(w->
crb);
100 cairo_surface_destroy(w->
buffer);
101 cairo_destroy(w->
cr);
102 cairo_surface_destroy(w->
surface);
116 XWindowAttributes attrs;
117 XGetWindowAttributes(wid->
app->
dpy, (Window)wid->
widget, &attrs);
118 if (wid->
width != attrs.width || wid->
height != attrs.height) {
130 debug_print(
"Widget_t configure callback width %i height %i\n", attrs.width, attrs.height);
146 int x,
int y,
int width,
int height) {
151 XSetWindowAttributes attributes;
152 attributes.save_under = True;
153 attributes.override_redirect = 0;
155 long event_mask = StructureNotifyMask|ExposureMask|KeyPressMask
156 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
157 |ButtonPressMask|Button1MotionMask;
161 w->
widget = XCreateWindow(app->
dpy, win , x, y, width, height, 0,
162 CopyFromParent, InputOutput, CopyFromParent,
163 CopyFromParent, &attributes);
166 XSetLocaleModifiers(
"");
167 w->
xim = XOpenIM(app->
dpy, 0, 0, 0);
169 XSetLocaleModifiers(
"@im=none");
170 w->
xim = XOpenIM(app->
dpy, 0, 0, 0);
173 w->
xic = XCreateIC(w->
xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
174 XNClientWindow, w->
widget, XNFocusWindow, w->
widget, NULL);
178 XSelectInput(app->
dpy, w->
widget, event_mask);
180 XSizeHints* win_size_hints;
181 win_size_hints = XAllocSizeHints();
182 win_size_hints->flags = PMinSize|PBaseSize|PWinGravity;
183 win_size_hints->min_width = width/2;
184 win_size_hints->min_height = height/2;
185 win_size_hints->base_width = width;
186 win_size_hints->base_height = height;
187 win_size_hints->win_gravity = CenterGravity;
188 XSetWMNormalHints(app->
dpy, w->
widget, win_size_hints);
189 XFree(win_size_hints);
192 DefaultVisual(app->
dpy, DefaultScreen(app->
dpy)), width, height);
194 assert(cairo_surface_status(w->
surface) == CAIRO_STATUS_SUCCESS);
196 cairo_select_font_face (w->
cr,
"Roboto", CAIRO_FONT_SLANT_NORMAL,
197 CAIRO_FONT_WEIGHT_NORMAL);
200 CAIRO_CONTENT_COLOR_ALPHA, width, height);
201 assert(cairo_surface_status(w->
buffer) == CAIRO_STATUS_SUCCESS);
203 cairo_select_font_face (w->
crb,
"Roboto", CAIRO_FONT_SLANT_NORMAL,
204 CAIRO_FONT_WEIGHT_NORMAL);
269 int x,
int y,
int width,
int height) {
274 XSetWindowAttributes attributes;
275 attributes.save_under = True;
276 attributes.override_redirect = True;
278 long event_mask = StructureNotifyMask|ExposureMask|KeyPressMask
279 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
280 |ButtonPressMask|Button1MotionMask;
284 w->
widget = XCreateWindow(app->
dpy, parent->
widget , x, y, width, height, 0,
285 CopyFromParent, InputOutput, CopyFromParent,
286 CopyFromParent|CWOverrideRedirect, &attributes);
289 XSetLocaleModifiers(
"");
290 w->
xim = XOpenIM(app->
dpy, 0, 0, 0);
292 XSetLocaleModifiers(
"@im=none");
293 w->
xim = XOpenIM(app->
dpy, 0, 0, 0);
296 w->
xic = XCreateIC(w->
xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
297 XNClientWindow, w->
widget, XNFocusWindow, w->
widget, NULL);
301 XSelectInput(app->
dpy, w->
widget, event_mask);
304 DefaultVisual(app->
dpy, DefaultScreen(app->
dpy)), width, height);
305 assert(cairo_surface_status(w->
surface) == CAIRO_STATUS_SUCCESS);
307 cairo_select_font_face (w->
cr,
"Roboto", CAIRO_FONT_SLANT_NORMAL,
308 CAIRO_FONT_WEIGHT_NORMAL);
311 CAIRO_CONTENT_COLOR_ALPHA, width, height);
312 assert(cairo_surface_status(w->
buffer) == CAIRO_STATUS_SUCCESS);
314 cairo_select_font_face (w->
crb,
"Roboto", CAIRO_FONT_SLANT_NORMAL,
315 CAIRO_FONT_WEIGHT_NORMAL);
381 debug_print(
"address of a is: %p\n", (
void*)event);
382 debug_print(
"address of b is: %p\n", (
void*)handler);
384 debug_print(
"address of a is: %p\n", (
void*)(*event));
435 XQueryPointer(wid->
app->
dpy, wid->
widget, &root, &child, &rx, &ry, &x, &y, &mask);
438 x, y, &x1, &y1, &child );
463 memset(&exp, 0,
sizeof(exp));
465 exp.xexpose.window = w->
widget;
466 XSendEvent(w->
app->
dpy, w->
widget, False, ExposureMask, (XEvent *)&exp);
472 cairo_push_group (wid->
cr);
476 XWindowAttributes attrs;
477 XGetWindowAttributes(wid->
app->
dpy, wid->
widget, &attrs);
480 cairo_set_source_surface (wid->
crb, parent->
buffer, -attrs.x, -attrs.y);
481 cairo_paint (wid->
crb);
484 cairo_push_group (wid->
crb);
486 cairo_pop_group_to_source (wid->
crb);
487 cairo_paint (wid->
crb);
489 cairo_set_source_surface (wid->
cr, wid->
buffer,0,0);
490 cairo_paint (wid->
cr);
492 cairo_pop_group_to_source (wid->
cr);
493 cairo_paint (wid->
cr);
499 XEvent *xev = (XEvent*)event;
502 case ConfigureNotify:
509 if (xev->xexpose.count == 0) {
516 if (wid->
state == 4)
break;
519 debug_print(
"Widget_t ButtonPress %i\n", xev->xbutton.button);
524 if (wid->
state == 4)
break;
530 debug_print(
"Widget_t ButtonRelease %i\n", xev->xbutton.button);
534 if (wid->
state == 4)
break;
537 debug_print(
"Widget_t KeyPress %u\n", xev->xkey.keycode);
541 if (wid->
state == 4)
break;
543 unsigned short is_retriggered = 0;
545 if (XEventsQueued(main->
dpy, QueuedAlready)) {
547 XPeekEvent(main->
dpy, &nev);
548 if (nev.type == KeyPress && nev.xkey.time == xev->xkey.time &&
549 nev.xkey.keycode == xev->xkey.keycode &&
550 (nev.xkey.keycode > 119 || nev.xkey.keycode < 110)) {
551 XNextEvent (main->
dpy, xev);
556 if (!is_retriggered) {
558 debug_print(
"Widget_t KeyRelease %u\n", xev->xkey.keycode);
565 if (wid->
state == 4)
break;
566 if(!(xev->xcrossing.state & Button1Mask)) {
576 if (wid->
state == 4)
break;
577 if(!(xev->xcrossing.state & Button1Mask)) {
587 if (wid->
state == 4)
break;
590 debug_print(
"Widget_t MotionNotify x = %i Y = %i \n",xev->xmotion.x,xev->xmotion.y );
594 if (xev->xclient.message_type == XInternAtom(wid->
app->
dpy,
"WIDGET_DESTROY", 1)) {
613 XConfigureEvent notify;
614 memset(¬ify, 0,
sizeof(notify));
615 notify.type = ConfigureNotify;
616 notify.display = w->
app->
dpy;
617 notify.send_event = True;
619 notify.window = w->
widget;
622 notify.width = width;
623 notify.height = height;
624 notify.border_width = 0;
626 notify.override_redirect = 1;
627 XSendEvent( w->
app->
dpy, w->
widget,
true, StructureNotifyMask, (XEvent*)¬ify );
632 memset(&event, 0,
sizeof(XEvent));
633 XWindowAttributes attr;
635 event.type = ButtonPress;
636 event.xbutton.same_screen =
true;
637 event.xbutton.root = None;
638 event.xbutton.window = w->
widget;
639 event.xbutton.subwindow = None;
642 event.xbutton.x_root = attr.x;
643 event.xbutton.y_root = attr.y;
644 event.xbutton.state = 0;
645 event.xbutton.button = Button1;
646 XSendEvent(w->
app->
dpy, PointerWindow, True, ButtonPressMask, &event);
651 memset(&event, 0,
sizeof(XEvent));
652 XWindowAttributes attr;
654 event.type = ButtonRelease;
655 event.xbutton.same_screen =
true;
656 event.xbutton.root = None;
657 event.xbutton.window = w->
widget;
658 event.xbutton.subwindow = None;
661 event.xbutton.x_root = attr.x;
662 event.xbutton.y_root = attr.y;
663 event.xbutton.state = 0;
664 event.xbutton.button = Button1;
665 XSendEvent(w->
app->
dpy, PointerWindow, True, ButtonReleaseMask, &event);
674 xscreen=DefaultScreenOfDisplay(w->
app->
dpy);
675 sprintf(buf,
"_NET_SYSTEM_TRAY_S%d",XScreenNumberOfScreen (xscreen));
676 Atom selection_atom = XInternAtom (w->
app->
dpy,buf,0);
678 Window tray = XGetSelectionOwner (w->
app->
dpy,selection_atom);
679 Atom visualatom = XInternAtom(w->
app->
dpy,
"_NET_SYSTEM_TRAY_VISUAL", False);
680 VisualID value = XVisualIDFromVisual(DefaultVisual(w->
app->
dpy, DefaultScreen(w->
app->
dpy)));
681 XChangeProperty(w->
app->
dpy, w->
widget, visualatom, XA_VISUALID, 32,
682 PropModeReplace, (
unsigned char*)&value, 1);
685 XSelectInput (w->
app->
dpy,tray,StructureNotifyMask);
687 memset(&event, 0,
sizeof(event));
688 event.xclient.type = ClientMessage;
689 event.xclient.window = tray;
690 event.xclient.message_type = XInternAtom (w->
app->
dpy,
"_NET_SYSTEM_TRAY_OPCODE", False );
691 event.xclient.format = 32;
692 event.xclient.data.l[0] = CurrentTime;
694 event.xclient.data.l[2] = w->
widget;
695 event.xclient.data.l[3] = 0;
696 event.xclient.data.l[4] = 0;
698 XSendEvent(w->
app->
dpy, tray, False, NoEventMask, &event);
702 Atom WM_DELETE_WINDOW = XInternAtom(w->
app->
dpy,
"WM_DELETE_WINDOW", True);
703 XClientMessageEvent xevent;
704 xevent.type = ClientMessage;
705 xevent.message_type = WM_DELETE_WINDOW;
706 xevent.display = w->
app->
dpy;
709 xevent.data.l[0] = WM_DELETE_WINDOW;
710 XSendEvent(w->
app->
dpy, w->
widget, 0, 0, (XEvent *)&xevent);
714 Atom QUIT_WIDGET = XInternAtom(w->
app->
dpy,
"WIDGET_DESTROY", False);
715 XClientMessageEvent xevent;
716 xevent.type = ClientMessage;
717 xevent.message_type = QUIT_WIDGET;
718 xevent.display = w->
app->
dpy;
719 xevent.window = w->
widget;
721 xevent.data.l[0] = 1;
722 XSendEvent(w->
app->
dpy, w->
widget, 0, 0, (XEvent *)&xevent);