7 #include "../../rtlib/unix/fb_private_scancodes_x11.h"
27 static pthread_cond_t
cond;
65 XPeekEvent(fb_x11.
display, &peek_event);
66 if ((peek_event.type == KeyPress) && (peek_event.xkey.keycode == event->xkey.keycode) &&
67 ((peek_event.xkey.time - event->xkey.time) < 2)) {
68 XNextEvent(fb_x11.
display, &peek_event);
80 if( XLookupString( &event->xkey, (
char *)key, 8,
NULL,
NULL ) == 1 ) {
122 pthread_mutex_lock(&
mutex);
123 pthread_cond_signal(&
cond);
124 pthread_mutex_unlock(&
mutex);
134 while (XPending(fb_x11.
display)) {
136 XNextEvent(fb_x11.
display, &event);
137 switch (event.type) {
191 switch (event.xbutton.button) {
201 switch (event.xbutton.button) {
223 switch (event.xbutton.button) {
227 default: e.
type = 0;
break;
231 case ConfigureNotify:
232 if( (event.xconfigure.width != fb_x11.
w) ||
233 ((
event.xconfigure.height != fb_x11.
h) &&
234 (event.xconfigure.height !=
real_h)) ) {
254 e.
ascii = ((key < 0) || (key > 0xFF)) ? 0 :
key;
267 e.
ascii = ((key < 0) || (key > 0xFF)) ? 0 :
key;
290 pthread_cond_signal(&
cond);
319 GrabModeAsync, GrabModeAsync, fb_x11.
window, None, CurrentTime) != GrabSuccess)
322 GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)
339 XUngrabPointer(fb_x11.
display, CurrentTime);
340 XUngrabKeyboard(fb_x11.
display, CurrentTime);
350 XMaskEvent(fb_x11.
display, StructureNotifyMask, &e);
351 }
while ((e.type != MapNotify) || (e.xmap.event != w));
376 XMoveResizeWindow(fb_x11.
display, fb_x11.
window, 0, 0, fb_x11.
w, fb_x11.
h);
388 event.xclient.type = ClientMessage;
389 event.xclient.send_event = True;
390 event.xclient.message_type = XInternAtom(fb_x11.
display,
"_NET_WM_STATE", False);
391 event.xclient.window = fb_x11.
wmwindow;
392 event.xclient.format = 32;
393 event.xclient.data.l[0] = 1;
394 event.xclient.data.l[1] = XInternAtom(fb_x11.
display,
"_NET_WM_STATE_ABOVE", False);
395 XSendEvent(fb_x11.
display,
root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
407 int fb_hX11Init(
char *title,
int w,
int h,
int depth,
int refresh_rate,
int flags)
409 XPixmapFormatValues *format;
410 XSetWindowAttributes attribs;
412 XpmAttributes xpm_attribs;
417 XRRScreenSize *sizes;
420 int i, num_formats, num_sizes, num_rates, supersized_h;
422 const char *intern_atoms[] = {
"_MOTIF_WM_HINTS",
"KWM_WIN_DECORATION",
"_WIN_HINTS" };
423 int intern_hints[] = { 0x2, 0, 0, 0, 0 };
430 fb_x11.
flags = flags;
443 fb_x11.
depth = depth;
451 format = XListPixmapFormats(fb_x11.
display, &num_formats);
452 for (i = 0; i < num_formats; i++) {
453 if (format[i].depth == fb_x11.
depth) {
454 if (format[i].bits_per_pixel == 16)
465 attribs.border_pixel = attribs.background_pixel = XBlackPixel(fb_x11.
display, fb_x11.
screen);
466 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
467 PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask | ExposureMask | StructureNotifyMask;
468 attribs.backing_store = NotUseful;
472 CWBackPixel | CWBorderPixel | CWEventMask | CWBackingStore | CWColormap, &attribs);
475 CWBackPixel | CWBorderPixel | CWEventMask | CWBackingStore | CWColormap, &attribs);
476 attribs.override_redirect = True;
479 CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask | CWBackingStore | CWColormap, &attribs);
485 hints.flags = IconPixmapHint | IconMaskHint;
486 xpm_attribs.valuemask = XpmReturnAllocPixels | XpmReturnExtensions;
491 size = XAllocSizeHints();
492 size->flags = PBaseSize | PMinSize | PMaxSize | PResizeInc;
493 size->min_width = size->base_width = fb_x11.
w;
494 size->min_height = size->base_height = fb_x11.
h;
496 size->max_width = size->min_width;
497 size->max_height = size->min_height;
499 size->max_width = XDisplayWidth(fb_x11.
display, fb_x11.
screen);
500 size->max_height = XDisplayHeight(fb_x11.
display, fb_x11.
screen);
502 size->width_inc = 0x10000;
503 size->height_inc = 0x10000;
506 size->max_width = size->min_width;
507 size->max_height = size->min_height;
512 for (i = 0; i < 3; i++) {
516 32, PropModeReplace, (
unsigned char *)&intern_hints[i], (i == 0) ? 5 : 1);
527 if (fb_x11.
visual->class == PseudoColor) {
533 pixmap = XCreatePixmap(fb_x11.
display, fb_x11.
window, 1, 1, 1);
534 gc_mask = GCFunction | GCForeground | GCBackground;
535 gc_values.function = GXcopy;
536 gc_values.foreground = gc_values.background = 0;
537 fb_x11.
gc = XCreateGC(fb_x11.
display, pixmap, gc_mask, &gc_values);
538 XDrawPoint(fb_x11.
display, pixmap, fb_x11.
gc, 0, 0);
540 color.pixel = color.red = color.green = color.blue = 0;
541 color.flags = DoRed | DoGreen | DoBlue;
544 XFreePixmap(fb_x11.
display, pixmap);
548 if (XRRQueryExtension(fb_x11.
display, &dummy, &dummy) &&
549 XRRQueryVersion(fb_x11.
display, &version, &dummy) && (version >= 1)) {
553 sizes = XRRConfigSizes(fb_x11.
config, &num_sizes);
554 for (i = 0; i < num_sizes; i++) {
555 if (sizes[i].width == fb_x11.
w) {
556 if (sizes[i].height == fb_x11.
h) {
561 else if (sizes[i].height == supersized_h) {
570 for (i = 0; i < num_rates; i++) {
595 pthread_mutex_lock(&
mutex);
598 pthread_mutex_unlock(&
mutex);
603 pthread_cond_destroy(&
cond);
604 pthread_mutex_destroy(&
mutex);
614 pthread_mutex_destroy(&
mutex);
615 pthread_cond_destroy(&
cond);
635 if (fb_x11.
window != None) {
648 XRRFreeScreenConfigInfo(fb_x11.
config);
658 pthread_mutex_lock(&
mutex);
664 XUnlockDisplay(fb_x11.
display);
665 pthread_mutex_unlock(&
mutex);
672 if (fb_x11.
visual->class == PseudoColor) {
674 color.red = (r << 8) | r;
675 color.green = (g << 8) | g;
676 color.blue = (b << 8) | b;
677 color.flags = DoRed | DoGreen | DoBlue;
691 unsigned int buttons_mask;
698 if (XQueryPointer(fb_x11.
display, fb_x11.
window, &root, &child, &root_x, &root_y, &win_x, &win_y, &buttons_mask)) {
701 *buttons = (buttons_mask & Button1Mask ? 0x1 : 0) |
702 (buttons_mask & Button3Mask ? 0x2 : 0) |
703 (buttons_mask & Button2Mask ? 0x4 : 0);
734 XUngrabPointer(fb_x11.
display, CurrentTime);
739 if (XGrabPointer(fb_x11.
display, fb_x11.
window, True, 0, GrabModeAsync, GrabModeAsync, fb_x11.
window, None, CurrentTime) == GrabSuccess)
753 Window window, root,
parent, *children;
754 XWindowAttributes attribs = { 0 };
756 unsigned int num_children;
767 XGetWindowAttributes(fb_x11.
display, window, &attribs);
768 XQueryTree(fb_x11.
display, window, &root, &parent, &children, &num_children);
769 if (children) XFree(children);
788 while (XCheckWindowEvent(fb_x11.
display, fb_x11.
window, PointerMotionMask, &event))
792 return ((attribs.x + dx) & 0xFFFF) | ((attribs.y + dy) << 16);
798 XRRScreenConfiguration *cfg;
799 XRRScreenSize *rr_sizes;
800 int i, *sizes =
NULL;
802 if ((depth != 8) && (depth != 15) && (depth != 16) && (depth != 24) && (depth != 32))
808 dpy = XOpenDisplay(
NULL);
815 cfg = XRRGetScreenInfo(dpy, XDefaultRootWindow(dpy));
819 rr_sizes = XRRConfigSizes(cfg, size);
820 if ((rr_sizes) && (*size > 0)) {
821 sizes = (
int *)malloc(*size *
sizeof(
int));
822 for (i = 0; i < *
size; i++)
823 sizes[i] = (rr_sizes[i].width << 16) | (rr_sizes[i].height);
826 XRRFreeScreenConfigInfo(cfg);
835 XRRScreenConfiguration *cfg;
839 dpy = XOpenDisplay(
NULL);
843 *width = XDisplayWidth(dpy, XDefaultScreen(dpy));
844 *height = XDisplayHeight(dpy, XDefaultScreen(dpy));
845 *depth = XDefaultDepth(dpy, XDefaultScreen(dpy));
846 if (XRRQueryExtension(dpy, &dummy, &dummy) &&
847 XRRQueryVersion(dpy, &version, &dummy) && (version >= 1)) {
849 cfg = XRRGetScreenInfo(dpy, XDefaultRootWindow(dpy));
851 *refresh = XRRConfigCurrentRate(cfg);
852 XRRFreeScreenConfigInfo(cfg);