summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-04-22 23:20:56 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-07-06 12:43:51 (GMT)
commit34774e7829716b4ef7c0bf54db78193a55f0aa61 (patch)
treea0796c5865070d790dc8ffe790bf9359bb74ebb1 /src/interface.c
parent3dd82d9ced79467e78be431aa92130542c355645 (diff)
downloadpowder-34774e7829716b4ef7c0bf54db78193a55f0aa61.zip
powder-34774e7829716b4ef7c0bf54db78193a55f0aa61.tar.gz
Basic clipboard_push_text support for linux
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/interface.c b/src/interface.c
index 4105754..002d4c5 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -24,6 +24,10 @@
SDLMod sdl_mod;
int sdl_key, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0;
+#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
+SDL_SysWMinfo sdl_wminfo;
+Atom XA_CLIPBOARD, XA_TARGETS;
+#endif
char *shift_0="`1234567890-=[]\\;',./";
char *shift_1="~!@#$%^&*()_+{}|:\"<>?";
@@ -2255,6 +2259,50 @@ int sdl_poll(void)
break;
case SDL_QUIT:
return 1;
+ case SDL_SYSWMEVENT:
+#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
+ if (event.syswm.msg->subsystem != SDL_SYSWM_X11)
+ break;
+ sdl_wminfo.info.x11.lock_func();
+ XEvent xe = event.syswm.msg->event.xevent;
+ if (xe.type==SelectionClear)
+ {
+ if (clipboard_text!=NULL) {
+ free(clipboard_text);
+ clipboard_text = NULL;
+ }
+ }
+ else if (xe.type==SelectionRequest)
+ {
+ XEvent xr;
+ xr.xselection.type = SelectionNotify;
+ xr.xselection.requestor = xe.xselectionrequest.requestor;
+ xr.xselection.selection = xe.xselectionrequest.selection;
+ xr.xselection.target = xe.xselectionrequest.target;
+ xr.xselection.property = xe.xselectionrequest.property;
+ xr.xselection.time = xe.xselectionrequest.time;
+ if (xe.xselectionrequest.target==XA_TARGETS)
+ {
+ // send list of supported formats
+ Atom targets[] = {XA_TARGETS, XA_STRING};
+ xr.xselection.property = xe.xselectionrequest.property;
+ XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char*)targets, (int)(sizeof(targets)/sizeof(Atom)));
+ }
+ // TODO: Supporting more targets would be nice
+ else if (xe.xselectionrequest.target==XA_STRING && clipboard_text)
+ {
+ XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, xe.xselectionrequest.target, 8, PropModeReplace, clipboard_text, strlen(clipboard_text)+1);
+ }
+ else
+ {
+ // refuse clipboard request
+ xr.xselection.property = None;
+ }
+ XSendEvent(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, 0, 0, &xr);
+ }
+ sdl_wminfo.info.x11.unlock_func();
+#endif
+ continue;
}
}
sdl_mod = SDL_GetModState();