Listen for clipboard-related events and handle them.

Listen for IPC-related events and handle them.
Changes after running indent-all.sh


git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@414 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Erik Forsberg 2003-06-06 11:10:48 +00:00
parent e83406e100
commit b21af4866e

162
xwin.c
View File

@ -1,4 +1,4 @@
/* /* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client. rdesktop: A Remote Desktop Protocol client.
User interface services - X Window System User interface services - X Window System
Copyright (C) Matthew Chapman 1999-2002 Copyright (C) Matthew Chapman 1999-2002
@ -23,6 +23,7 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include "rdesktop.h" #include "rdesktop.h"
#include "xproto.h"
extern int width; extern int width;
extern int height; extern int height;
@ -38,9 +39,10 @@ BOOL focused;
BOOL mouse_in_wnd; BOOL mouse_in_wnd;
Display *display; Display *display;
Time last_gesturetime;
static int x_socket; static int x_socket;
static Screen *screen; static Screen *screen;
static Window wnd; Window wnd;
static GC gc; static GC gc;
static Visual *visual; static Visual *visual;
static int depth; static int depth;
@ -50,6 +52,9 @@ static XIC IC;
static XModifierKeymap *mod_map; static XModifierKeymap *mod_map;
static Cursor current_cursor; static Cursor current_cursor;
static Atom protocol_atom, kill_atom; static Atom protocol_atom, kill_atom;
static long input_mask; /* Needs to be global since we access it in
both ui_create_window and the PropertyNotify
callback functions */
/* endianness */ /* endianness */
static BOOL host_be; static BOOL host_be;
@ -85,6 +90,21 @@ typedef struct
} }
PixelColour; PixelColour;
struct _PropNotifyCb;
typedef struct _PropNotifyCb
{
Window wnd;
Atom atom;
void (*callback) (XPropertyEvent *);
struct _PropNotifyCb *next;
}
PropNotifyCb;
static PropNotifyCb *propnotify_callbacks = NULL;
#define FILL_RECTANGLE(x,y,cx,cy)\ #define FILL_RECTANGLE(x,y,cx,cy)\
{ \ { \
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ XFillRectangle(display, wnd, gc, x, y, cx, cy); \
@ -614,6 +634,8 @@ ui_init(void)
/* todo take this out when high colour is done */ /* todo take this out when high colour is done */
printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth); printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
return True; return True;
} }
@ -640,7 +662,7 @@ ui_create_window(void)
XClassHint *classhints; XClassHint *classhints;
XSizeHints *sizehints; XSizeHints *sizehints;
int wndwidth, wndheight; int wndwidth, wndheight;
long input_mask, ic_input_mask; long ic_input_mask;
XEvent xevent; XEvent xevent;
wndwidth = fullscreen ? WidthOfScreen(screen) : width; wndwidth = fullscreen ? WidthOfScreen(screen) : width;
@ -754,6 +776,21 @@ xwin_toggle_fullscreen(void)
} }
} }
static void
xwin_process_propertynotify(XPropertyEvent * xev)
{
PropNotifyCb *this = propnotify_callbacks;
while (NULL != this)
{
if (xev->window == this->wnd && xev->atom == this->atom)
{
this->callback(xev);
}
this = this->next;
}
}
/* Process all events in Xlib queue /* Process all events in Xlib queue
Returns 0 after user quit, 1 otherwise */ Returns 0 after user quit, 1 otherwise */
static int static int
@ -793,6 +830,7 @@ xwin_process_events(void)
break; break;
case KeyPress: case KeyPress:
last_gesturetime = ((XKeyEvent *) & xevent)->time;
if (IC != NULL) if (IC != NULL)
/* Multi_key compatible version */ /* Multi_key compatible version */
{ {
@ -833,6 +871,7 @@ xwin_process_events(void)
break; break;
case KeyRelease: case KeyRelease:
last_gesturetime = ((XKeyEvent *) & xevent)->time;
XLookupString((XKeyEvent *) & xevent, str, XLookupString((XKeyEvent *) & xevent, str,
sizeof(str), &keysym, NULL); sizeof(str), &keysym, NULL);
@ -853,10 +892,12 @@ xwin_process_events(void)
break; break;
case ButtonPress: case ButtonPress:
last_gesturetime = ((XButtonEvent *) & xevent)->time;
flags = MOUSE_FLAG_DOWN; flags = MOUSE_FLAG_DOWN;
/* fall through */ /* fall through */
case ButtonRelease: case ButtonRelease:
last_gesturetime = ((XButtonEvent *) & xevent)->time;
button = xkeymap_translate_button(xevent.xbutton.button); button = xkeymap_translate_button(xevent.xbutton.button);
if (button == 0) if (button == 0)
break; break;
@ -992,6 +1033,22 @@ xwin_process_events(void)
mod_map = XGetModifierMapping(display); mod_map = XGetModifierMapping(display);
} }
break; break;
/* Clipboard stuff */
case SelectionClear:
cliprdr_handle_SelectionClear();
break;
case SelectionNotify:
cliprdr_handle_SelectionNotify((XSelectionEvent *) & xevent);
break;
case SelectionRequest:
cliprdr_handle_SelectionRequest((XSelectionRequestEvent *) &
xevent);
break;
case PropertyNotify:
xwin_process_propertynotify((XPropertyEvent *) & xevent);
break;
} }
} }
@ -1398,7 +1455,8 @@ ui_patblt(uint8 opcode,
break; break;
case 2: /* Hatch */ case 2: /* Hatch */
fill = (Pixmap) ui_create_glyph(8, 8, hatch_patterns + brush->pattern[0] * 8); fill = (Pixmap) ui_create_glyph(8, 8,
hatch_patterns + brush->pattern[0] * 8);
SET_FOREGROUND(bgcolour); SET_FOREGROUND(bgcolour);
SET_BACKGROUND(fgcolour); SET_BACKGROUND(fgcolour);
XSetFillStyle(display, gc, FillOpaqueStippled); XSetFillStyle(display, gc, FillOpaqueStippled);
@ -1699,3 +1757,99 @@ ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
XFree(image); XFree(image);
} }
void
xwin_register_propertynotify(Window event_wnd, Atom atom,
void (*propertycallback) (XPropertyEvent *))
{
PropNotifyCb *this;
int window_already_registrered = 0;
if (NULL != propnotify_callbacks)
{
this = propnotify_callbacks;
if (event_wnd == this->wnd)
{
window_already_registrered = 1;
if (atom == this->atom)
return;
}
while (NULL != this->next)
{
if (event_wnd == this->wnd)
{
window_already_registrered = 1;
if (atom == this->atom)
return;
/* Find last entry in list */
}
this = this->next;
}
this->next = xmalloc(sizeof(PropNotifyCb));
this->next->next = NULL;
this = this->next;
}
else
{
this = xmalloc(sizeof(PropNotifyCb));
this->next = NULL;
propnotify_callbacks = this;
}
if (!window_already_registrered)
{
if (wnd == event_wnd)
XSelectInput(display, wnd, input_mask | PropertyChangeMask);
else
XSelectInput(display, event_wnd, PropertyChangeMask);
}
this->wnd = event_wnd;
this->atom = atom;
this->callback = propertycallback;
}
void
xwin_deregister_propertynotify(Window event_wnd, Atom atom)
{
PropNotifyCb *this = propnotify_callbacks;
PropNotifyCb *prev;
int window_needed = 0;
prev = this;
while (NULL != this)
{
if (event_wnd == this->wnd)
{
if (atom == this->atom)
{
if (prev == this)
{
propnotify_callbacks = this->next;
}
else
{
prev->next = this->next;
}
xfree(this);
continue;
}
else
{
window_needed = 1;
}
}
prev = this;
this = this->next;
}
if (!window_needed)
{
if (wnd != event_wnd)
{
XSelectInput(display, event_wnd, NoEventMask);
}
else
{
XSelectInput(display, wnd, input_mask);
}
}
}