22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
#include <time.h> |
#include <time.h> |
24 |
#include <errno.h> |
#include <errno.h> |
|
#define XK_MISCELLANY |
|
|
#include <X11/keysymdef.h> |
|
25 |
#include "rdesktop.h" |
#include "rdesktop.h" |
|
#include "scancodes.h" |
|
26 |
|
|
27 |
extern int width; |
extern int width; |
28 |
extern int height; |
extern int height; |
217 |
} |
} |
218 |
|
|
219 |
BOOL |
BOOL |
220 |
ui_init() |
ui_init(void) |
221 |
{ |
{ |
222 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
223 |
uint16 test; |
uint16 test; |
278 |
|
|
279 |
if (ownbackstore) |
if (ownbackstore) |
280 |
{ |
{ |
281 |
backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
backstore = |
282 |
|
XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
283 |
|
|
284 |
/* clear to prevent rubbish being exposed at startup */ |
/* clear to prevent rubbish being exposed at startup */ |
285 |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
294 |
} |
} |
295 |
|
|
296 |
void |
void |
297 |
ui_deinit() |
ui_deinit(void) |
298 |
{ |
{ |
299 |
if (IM != NULL) |
if (IM != NULL) |
300 |
XCloseIM(IM); |
XCloseIM(IM); |
308 |
} |
} |
309 |
|
|
310 |
BOOL |
BOOL |
311 |
ui_create_window() |
ui_create_window(void) |
312 |
{ |
{ |
313 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
314 |
XClassHint *classhints; |
XClassHint *classhints; |
317 |
long input_mask, ic_input_mask; |
long input_mask, ic_input_mask; |
318 |
XEvent xevent; |
XEvent xevent; |
319 |
|
|
320 |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
321 |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
322 |
|
|
323 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
351 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
352 |
StructureNotifyMask | FocusChangeMask; |
StructureNotifyMask | FocusChangeMask; |
353 |
|
|
|
if (grab_keyboard) |
|
|
input_mask |= EnterWindowMask | LeaveWindowMask; |
|
354 |
if (sendmotion) |
if (sendmotion) |
355 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
356 |
if (ownbackstore) |
if (ownbackstore) |
361 |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
362 |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
363 |
|
|
364 |
if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
if ((IC != NULL) |
365 |
|
&& (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
366 |
input_mask |= ic_input_mask; |
input_mask |= ic_input_mask; |
367 |
} |
} |
368 |
|
|
370 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
371 |
|
|
372 |
/* wait for MapNotify */ |
/* wait for MapNotify */ |
373 |
do { |
do |
374 |
|
{ |
375 |
XMaskEvent(display, StructureNotifyMask, &xevent); |
XMaskEvent(display, StructureNotifyMask, &xevent); |
376 |
} while (xevent.type != MapNotify); |
} |
377 |
|
while (xevent.type != MapNotify); |
378 |
|
|
379 |
if (fullscreen) |
if (fullscreen) |
380 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
383 |
} |
} |
384 |
|
|
385 |
void |
void |
386 |
ui_destroy_window() |
ui_destroy_window(void) |
387 |
{ |
{ |
388 |
if (IC != NULL) |
if (IC != NULL) |
389 |
XDestroyIC(IC); |
XDestroyIC(IC); |
392 |
} |
} |
393 |
|
|
394 |
void |
void |
395 |
xwin_toggle_fullscreen() |
xwin_toggle_fullscreen(void) |
396 |
{ |
{ |
397 |
Pixmap contents = 0; |
Pixmap contents = 0; |
398 |
|
|
418 |
|
|
419 |
/* Process all events in Xlib queue */ |
/* Process all events in Xlib queue */ |
420 |
static void |
static void |
421 |
xwin_process_events() |
xwin_process_events(void) |
422 |
{ |
{ |
423 |
XEvent xevent; |
XEvent xevent; |
424 |
KeySym keysym; |
KeySym keysym; |
520 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
521 |
break; |
break; |
522 |
|
|
523 |
case EnterNotify: |
case FocusIn: |
524 |
|
reset_modifier_keys(); |
525 |
if (grab_keyboard) |
if (grab_keyboard) |
526 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
527 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
528 |
break; |
break; |
529 |
|
|
530 |
case LeaveNotify: |
case FocusOut: |
531 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
532 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
533 |
break; |
break; |
534 |
|
|
|
case FocusIn: |
|
|
reset_modifier_keys(); |
|
|
break; |
|
|
|
|
535 |
case Expose: |
case Expose: |
536 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
537 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
783 |
long nDist = nMinDist; |
long nDist = nMinDist; |
784 |
|
|
785 |
/* only get the colors once */ |
/* only get the colors once */ |
786 |
while( colLookup-- ){ |
while (colLookup--) |
787 |
|
{ |
788 |
xc_cache[colLookup].pixel = colLookup; |
xc_cache[colLookup].pixel = colLookup; |
789 |
xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0; |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
790 |
|
xc_cache[colLookup].blue = 0; |
791 |
xc_cache[colLookup].flags = 0; |
xc_cache[colLookup].flags = 0; |
792 |
XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]); |
XQueryColor(display, |
793 |
|
DefaultColormap(display, DefaultScreen(display)), |
794 |
|
&xc_cache[colLookup]); |
795 |
} |
} |
796 |
colLookup = 0; |
colLookup = 0; |
797 |
|
|
798 |
/* approximate the pixel */ |
/* approximate the pixel */ |
799 |
while( j-- ){ |
while (j--) |
800 |
if( xc_cache[j].flags ){ |
{ |
801 |
nDist = |
if (xc_cache[j].flags) |
802 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) * |
{ |
803 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) + |
nDist = ((long) (xc_cache[j].red >> 8) - |
804 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) * |
(long) (xentry.red >> 8)) * |
805 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) + |
((long) (xc_cache[j].red >> 8) - |
806 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) * |
(long) (xentry.red >> 8)) + |
807 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)); |
((long) (xc_cache[j].green >> 8) - |
808 |
|
(long) (xentry.green >> 8)) * |
809 |
|
((long) (xc_cache[j].green >> 8) - |
810 |
|
(long) (xentry.green >> 8)) + |
811 |
|
((long) (xc_cache[j].blue >> 8) - |
812 |
|
(long) (xentry.blue >> 8)) * |
813 |
|
((long) (xc_cache[j].blue >> 8) - |
814 |
|
(long) (xentry.blue >> 8)); |
815 |
} |
} |
816 |
if( nDist < nMinDist ){ |
if (nDist < nMinDist) |
817 |
|
{ |
818 |
nMinDist = nDist; |
nMinDist = nDist; |
819 |
xentry.pixel = j; |
xentry.pixel = j; |
820 |
} |
} |
823 |
colour = xentry.pixel; |
colour = xentry.pixel; |
824 |
|
|
825 |
/* update our cache */ |
/* update our cache */ |
826 |
if( xentry.pixel < 256 ){ |
if (xentry.pixel < 256) |
827 |
|
{ |
828 |
xc_cache[xentry.pixel].red = xentry.red; |
xc_cache[xentry.pixel].red = xentry.red; |
829 |
xc_cache[xentry.pixel].green = xentry.green; |
xc_cache[xentry.pixel].green = xentry.green; |
830 |
xc_cache[xentry.pixel].blue = xentry.blue; |
xc_cache[xentry.pixel].blue = xentry.blue; |
864 |
} |
} |
865 |
|
|
866 |
void |
void |
867 |
ui_reset_clip() |
ui_reset_clip(void) |
868 |
{ |
{ |
869 |
XRectangle rect; |
XRectangle rect; |
870 |
|
|
876 |
} |
} |
877 |
|
|
878 |
void |
void |
879 |
ui_bell() |
ui_bell(void) |
880 |
{ |
{ |
881 |
XBell(display, 0); |
XBell(display, 0); |
882 |
} |
} |