spmenu/libs/x11/event.c

80 lines
2.1 KiB
C
Raw Normal View History

2023-05-14 00:21:16 +02:00
/* See LICENSE file for copyright and license details. */
void eventloop(void) {
2023-05-08 23:00:45 +02:00
XEvent ev;
int noimg = 0;
2023-05-08 23:00:45 +02:00
while (!XNextEvent(dpy, &ev)) {
if (XFilterEvent(&ev, None))
continue;
2023-05-08 23:00:45 +02:00
switch(ev.type) {
case DestroyNotify:
if (ev.xdestroywindow.window != win)
break;
cleanup();
exit(1);
case ButtonPress:
buttonpress(&ev);
noimg = 0;
break;
case MotionNotify: // currently does nothing
break;
case Expose:
if (ev.xexpose.count == 0)
drw_map(drw, win, 0, 0, mw, mh);
break;
case FocusIn:
// regrab focus from parent window
if (ev.xfocus.window != win)
grabfocus();
break;
case KeyPress: // read key array and call functions
if (incremental) {
puts(text);
fflush(stdout);
}
keypress(&ev);
noimg = 1;
break;
case SelectionNotify: // paste selection
if (ev.xselection.property == utf8)
pastesel();
break;
case VisibilityNotify:
if (ev.xvisibility.state != VisibilityUnobscured)
XRaiseWindow(dpy, win);
break;
case KeyRelease:
getcapsstate();
drawmenu();
noimg = 0;
break;
2023-05-08 23:00:45 +02:00
}
if (listfile) {
readfile();
if (listchanged) {
match();
2023-05-07 15:33:09 +02:00
for (int i = 0; i < itemnumber; i++) {
if (sel && sel->right && (sel = sel->right) == next) {
curr = next;
}
}
drawmenu();
}
}
// redraw image on X11 event
if (!noimg)
2023-05-08 23:00:45 +02:00
#if USEIMAGE
drawimage();
#else
;
2023-05-08 23:00:45 +02:00
#endif
}
}