42 |
static int bpp; |
static int bpp; |
43 |
static XIM IM; |
static XIM IM; |
44 |
static XIC IC; |
static XIC IC; |
45 |
|
static XModifierKeymap *mod_map; |
46 |
static Cursor current_cursor; |
static Cursor current_cursor; |
47 |
|
|
48 |
/* endianness */ |
/* endianness */ |
184 |
} |
} |
185 |
|
|
186 |
BOOL |
BOOL |
187 |
get_key_state(int keysym) |
get_key_state(uint32 keysym, unsigned int state) |
188 |
{ |
{ |
189 |
int keysymMask = 0, modifierpos, key; |
int modifierpos, key, keysymMask = 0; |
|
Window wDummy1, wDummy2; |
|
|
int iDummy3, iDummy4, iDummy5, iDummy6; |
|
|
unsigned int current_state; |
|
190 |
int offset; |
int offset; |
191 |
|
|
|
XModifierKeymap *map = XGetModifierMapping(display); |
|
192 |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
193 |
|
|
194 |
if (keycode == NoSymbol) |
if (keycode == NoSymbol) |
196 |
|
|
197 |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
198 |
{ |
{ |
199 |
offset = map->max_keypermod * modifierpos; |
offset = mod_map->max_keypermod * modifierpos; |
200 |
|
|
201 |
for (key = 0; key < map->max_keypermod; key++) |
for (key = 0; key < mod_map->max_keypermod; key++) |
202 |
{ |
{ |
203 |
if (map->modifiermap[offset + key] == keycode) |
if (mod_map->modifiermap[offset + key] == keycode) |
204 |
keysymMask = 1 << modifierpos; |
keysymMask |= 1 << modifierpos; |
205 |
} |
} |
206 |
} |
} |
207 |
|
|
208 |
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
return (state & keysymMask) ? True : False; |
|
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
|
|
|
|
XFreeModifiermap(map); |
|
|
|
|
|
return (current_state & keysymMask) ? True : False; |
|
209 |
} |
} |
210 |
|
|
211 |
BOOL |
BOOL |
212 |
ui_init() |
ui_init(void) |
213 |
{ |
{ |
214 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
215 |
uint16 test; |
uint16 test; |
270 |
|
|
271 |
if (ownbackstore) |
if (ownbackstore) |
272 |
{ |
{ |
273 |
backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
backstore = |
274 |
|
XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
275 |
|
|
276 |
/* clear to prevent rubbish being exposed at startup */ |
/* clear to prevent rubbish being exposed at startup */ |
277 |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
278 |
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
279 |
} |
} |
280 |
|
|
281 |
|
mod_map = XGetModifierMapping(display); |
282 |
|
|
283 |
if (enable_compose) |
if (enable_compose) |
284 |
IM = XOpenIM(display, NULL, NULL, NULL); |
IM = XOpenIM(display, NULL, NULL, NULL); |
285 |
|
|
288 |
} |
} |
289 |
|
|
290 |
void |
void |
291 |
ui_deinit() |
ui_deinit(void) |
292 |
{ |
{ |
293 |
if (IM != NULL) |
if (IM != NULL) |
294 |
XCloseIM(IM); |
XCloseIM(IM); |
295 |
|
|
296 |
|
XFreeModifierMap(mod_map); |
297 |
|
|
298 |
if (ownbackstore) |
if (ownbackstore) |
299 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
300 |
|
|
304 |
} |
} |
305 |
|
|
306 |
BOOL |
BOOL |
307 |
ui_create_window() |
ui_create_window(void) |
308 |
{ |
{ |
309 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
310 |
XClassHint *classhints; |
XClassHint *classhints; |
313 |
long input_mask, ic_input_mask; |
long input_mask, ic_input_mask; |
314 |
XEvent xevent; |
XEvent xevent; |
315 |
|
|
316 |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
317 |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
318 |
|
|
319 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
347 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
348 |
StructureNotifyMask | FocusChangeMask; |
StructureNotifyMask | FocusChangeMask; |
349 |
|
|
|
if (grab_keyboard) |
|
|
input_mask |= EnterWindowMask | LeaveWindowMask; |
|
350 |
if (sendmotion) |
if (sendmotion) |
351 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
352 |
if (ownbackstore) |
if (ownbackstore) |
357 |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
358 |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
359 |
|
|
360 |
if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
if ((IC != NULL) |
361 |
|
&& (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
362 |
input_mask |= ic_input_mask; |
input_mask |= ic_input_mask; |
363 |
} |
} |
364 |
|
|
366 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
367 |
|
|
368 |
/* wait for MapNotify */ |
/* wait for MapNotify */ |
369 |
do { |
do |
370 |
|
{ |
371 |
XMaskEvent(display, StructureNotifyMask, &xevent); |
XMaskEvent(display, StructureNotifyMask, &xevent); |
372 |
} while (xevent.type != MapNotify); |
} |
373 |
|
while (xevent.type != MapNotify); |
374 |
|
|
375 |
if (fullscreen) |
if (fullscreen) |
376 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
379 |
} |
} |
380 |
|
|
381 |
void |
void |
382 |
ui_destroy_window() |
ui_destroy_window(void) |
383 |
{ |
{ |
384 |
if (IC != NULL) |
if (IC != NULL) |
385 |
XDestroyIC(IC); |
XDestroyIC(IC); |
388 |
} |
} |
389 |
|
|
390 |
void |
void |
391 |
xwin_toggle_fullscreen() |
xwin_toggle_fullscreen(void) |
392 |
{ |
{ |
393 |
Pixmap contents = 0; |
Pixmap contents = 0; |
394 |
|
|
414 |
|
|
415 |
/* Process all events in Xlib queue */ |
/* Process all events in Xlib queue */ |
416 |
static void |
static void |
417 |
xwin_process_events() |
xwin_process_events(void) |
418 |
{ |
{ |
419 |
XEvent xevent; |
XEvent xevent; |
420 |
KeySym keysym; |
KeySym keysym; |
421 |
uint16 button, flags; |
uint16 button, flags; |
422 |
uint32 ev_time; |
uint32 ev_time; |
423 |
key_translation tr; |
key_translation tr; |
|
char *ksname = NULL; |
|
424 |
char str[256]; |
char str[256]; |
425 |
Status status; |
Status status; |
426 |
|
unsigned int state; |
427 |
|
Window wdummy; |
428 |
|
int dummy; |
429 |
|
|
430 |
while (XPending(display) > 0) |
while (XPending(display) > 0) |
431 |
{ |
{ |
437 |
continue; |
continue; |
438 |
} |
} |
439 |
|
|
|
ev_time = time(NULL); |
|
440 |
flags = 0; |
flags = 0; |
441 |
|
|
442 |
switch (xevent.type) |
switch (xevent.type) |
463 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
464 |
} |
} |
465 |
|
|
466 |
ksname = get_ksname(keysym); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
|
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
|
467 |
|
|
468 |
if (handle_special_keys(keysym, ev_time, True)) |
ev_time = time(NULL); |
469 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
470 |
break; |
break; |
471 |
|
|
472 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
479 |
|
|
480 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
481 |
break; |
break; |
482 |
|
|
483 |
case KeyRelease: |
case KeyRelease: |
484 |
XLookupString((XKeyEvent *) & xevent, str, |
XLookupString((XKeyEvent *) & xevent, str, |
485 |
sizeof(str), &keysym, NULL); |
sizeof(str), &keysym, NULL); |
486 |
|
|
|
ksname = get_ksname(keysym); |
|
487 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
488 |
ksname)); |
get_ksname(keysym))); |
489 |
|
|
490 |
if (handle_special_keys(keysym, ev_time, False)) |
ev_time = time(NULL); |
491 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) |
492 |
break; |
break; |
493 |
|
|
494 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
509 |
if (button == 0) |
if (button == 0) |
510 |
break; |
break; |
511 |
|
|
512 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
513 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
514 |
break; |
break; |
515 |
|
|
516 |
case MotionNotify: |
case MotionNotify: |
517 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
518 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
519 |
break; |
break; |
520 |
|
|
521 |
case EnterNotify: |
case FocusIn: |
522 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
523 |
|
reset_modifier_keys(state); |
524 |
if (grab_keyboard) |
if (grab_keyboard) |
525 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
526 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
527 |
break; |
break; |
528 |
|
|
529 |
case LeaveNotify: |
case FocusOut: |
530 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
531 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
532 |
break; |
break; |
533 |
|
|
|
case FocusIn: |
|
|
reset_modifier_keys(); |
|
|
break; |
|
|
|
|
534 |
case Expose: |
case Expose: |
535 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
536 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
545 |
if (xevent.xmapping.request == MappingKeyboard |
if (xevent.xmapping.request == MappingKeyboard |
546 |
|| xevent.xmapping.request == MappingModifier) |
|| xevent.xmapping.request == MappingModifier) |
547 |
XRefreshKeyboardMapping(&xevent.xmapping); |
XRefreshKeyboardMapping(&xevent.xmapping); |
548 |
|
|
549 |
|
if (xevent.xmapping.request == MappingModifier) |
550 |
|
{ |
551 |
|
XFreeModifierMap(mod_map); |
552 |
|
mod_map = XGetModifierMapping(display); |
553 |
|
} |
554 |
break; |
break; |
555 |
|
|
556 |
} |
} |
788 |
long nDist = nMinDist; |
long nDist = nMinDist; |
789 |
|
|
790 |
/* only get the colors once */ |
/* only get the colors once */ |
791 |
while( colLookup-- ){ |
while (colLookup--) |
792 |
|
{ |
793 |
xc_cache[colLookup].pixel = colLookup; |
xc_cache[colLookup].pixel = colLookup; |
794 |
xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0; |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
795 |
|
xc_cache[colLookup].blue = 0; |
796 |
xc_cache[colLookup].flags = 0; |
xc_cache[colLookup].flags = 0; |
797 |
XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]); |
XQueryColor(display, |
798 |
|
DefaultColormap(display, DefaultScreen(display)), |
799 |
|
&xc_cache[colLookup]); |
800 |
} |
} |
801 |
colLookup = 0; |
colLookup = 0; |
802 |
|
|
803 |
/* approximate the pixel */ |
/* approximate the pixel */ |
804 |
while( j-- ){ |
while (j--) |
805 |
if( xc_cache[j].flags ){ |
{ |
806 |
nDist = |
if (xc_cache[j].flags) |
807 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) * |
{ |
808 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) + |
nDist = ((long) (xc_cache[j].red >> 8) - |
809 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) * |
(long) (xentry.red >> 8)) * |
810 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) + |
((long) (xc_cache[j].red >> 8) - |
811 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) * |
(long) (xentry.red >> 8)) + |
812 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)); |
((long) (xc_cache[j].green >> 8) - |
813 |
|
(long) (xentry.green >> 8)) * |
814 |
|
((long) (xc_cache[j].green >> 8) - |
815 |
|
(long) (xentry.green >> 8)) + |
816 |
|
((long) (xc_cache[j].blue >> 8) - |
817 |
|
(long) (xentry.blue >> 8)) * |
818 |
|
((long) (xc_cache[j].blue >> 8) - |
819 |
|
(long) (xentry.blue >> 8)); |
820 |
} |
} |
821 |
if( nDist < nMinDist ){ |
if (nDist < nMinDist) |
822 |
|
{ |
823 |
nMinDist = nDist; |
nMinDist = nDist; |
824 |
xentry.pixel = j; |
xentry.pixel = j; |
825 |
} |
} |
828 |
colour = xentry.pixel; |
colour = xentry.pixel; |
829 |
|
|
830 |
/* update our cache */ |
/* update our cache */ |
831 |
if( xentry.pixel < 256 ){ |
if (xentry.pixel < 256) |
832 |
|
{ |
833 |
xc_cache[xentry.pixel].red = xentry.red; |
xc_cache[xentry.pixel].red = xentry.red; |
834 |
xc_cache[xentry.pixel].green = xentry.green; |
xc_cache[xentry.pixel].green = xentry.green; |
835 |
xc_cache[xentry.pixel].blue = xentry.blue; |
xc_cache[xentry.pixel].blue = xentry.blue; |
869 |
} |
} |
870 |
|
|
871 |
void |
void |
872 |
ui_reset_clip() |
ui_reset_clip(void) |
873 |
{ |
{ |
874 |
XRectangle rect; |
XRectangle rect; |
875 |
|
|
881 |
} |
} |
882 |
|
|
883 |
void |
void |
884 |
ui_bell() |
ui_bell(void) |
885 |
{ |
{ |
886 |
XBell(display, 0); |
XBell(display, 0); |
887 |
} |
} |