mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-14 12:24:04 +02:00
Basic clipboard_push_text support for linux
This commit is contained in:
committed by
Simon Robertshaw
parent
3dd82d9ced
commit
34774e7829
2
Makefile
2
Makefile
@@ -9,7 +9,7 @@ PYCOMMAND := $(PY_BIN) getheader.py
|
|||||||
|
|
||||||
CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -Iincludes/
|
CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -Iincludes/
|
||||||
OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
|
OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
|
||||||
LFLAGS := -lpthread -lSDL -lm -lbz2 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS)
|
LFLAGS := -lpthread -lSDL -lm -lbz2 -lX11 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS)
|
||||||
LFLAGS_X := -lm -lbz2 -lSDLmain -I/Library/Frameworks/Python.framework/Versions/$(PY_VERSION)/include/python$(PY_VERSION)
|
LFLAGS_X := -lm -lbz2 -lSDLmain -I/Library/Frameworks/Python.framework/Versions/$(PY_VERSION)/include/python$(PY_VERSION)
|
||||||
MFLAGS_SSE3 := -march=native -DX86 -DX86_SSE3 -msse3
|
MFLAGS_SSE3 := -march=native -DX86 -DX86_SSE3 -msse3
|
||||||
MFLAGS_SSE2 := -march=native -DX86 -DX86_SSE2 -msse2
|
MFLAGS_SSE2 := -march=native -DX86 -DX86_SSE2 -msse2
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
#ifndef INTERFACE_H
|
#ifndef INTERFACE_H
|
||||||
#define INTERFACE_H
|
#define INTERFACE_H
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
|
||||||
|
#include <SDL/SDL_syswm.h>
|
||||||
|
#endif
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
struct menu_section
|
struct menu_section
|
||||||
@@ -130,6 +133,11 @@ typedef struct ui_richtext ui_richtext;
|
|||||||
int SLALT;
|
int SLALT;
|
||||||
extern SDLMod sdl_mod;
|
extern SDLMod sdl_mod;
|
||||||
extern int sdl_key, sdl_wheel, sdl_caps, sdl_ascii, sdl_zoom_trig;
|
extern int sdl_key, sdl_wheel, sdl_caps, sdl_ascii, sdl_zoom_trig;
|
||||||
|
#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
|
||||||
|
extern SDL_SysWMinfo sdl_wminfo;
|
||||||
|
extern Atom XA_CLIPBOARD, XA_TARGETS;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern char *shift_0;
|
extern char *shift_0;
|
||||||
extern char *shift_1;
|
extern char *shift_1;
|
||||||
extern int svf_messages;
|
extern int svf_messages;
|
||||||
|
@@ -64,6 +64,8 @@ void clipboard_push_text(char * text);
|
|||||||
|
|
||||||
char * clipboard_pull_text();
|
char * clipboard_pull_text();
|
||||||
|
|
||||||
|
extern char *clipboard_text;
|
||||||
|
|
||||||
int register_extension();
|
int register_extension();
|
||||||
|
|
||||||
int cpu_check(void);
|
int cpu_check(void);
|
||||||
|
@@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
SDLMod sdl_mod;
|
SDLMod sdl_mod;
|
||||||
int sdl_key, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0;
|
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_0="`1234567890-=[]\\;',./";
|
||||||
char *shift_1="~!@#$%^&*()_+{}|:\"<>?";
|
char *shift_1="~!@#$%^&*()_+{}|:\"<>?";
|
||||||
@@ -2255,6 +2259,50 @@ int sdl_poll(void)
|
|||||||
break;
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
return 1;
|
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();
|
sdl_mod = SDL_GetModState();
|
||||||
|
12
src/misc.c
12
src/misc.c
@@ -20,6 +20,8 @@
|
|||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *clipboard_text = NULL;
|
||||||
|
|
||||||
//Signum function
|
//Signum function
|
||||||
#if defined(WIN32) && !defined(__GNUC__)
|
#if defined(WIN32) && !defined(__GNUC__)
|
||||||
_inline int isign(float i)
|
_inline int isign(float i)
|
||||||
@@ -421,6 +423,16 @@ void clipboard_push_text(char * text)
|
|||||||
SetClipboardData(CF_TEXT, cbuffer);
|
SetClipboardData(CF_TEXT, cbuffer);
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
}
|
}
|
||||||
|
#elif (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
|
||||||
|
if (clipboard_text!=NULL) {
|
||||||
|
free(clipboard_text);
|
||||||
|
clipboard_text = NULL;
|
||||||
|
}
|
||||||
|
clipboard_text = mystrdup(text);
|
||||||
|
sdl_wminfo.info.x11.lock_func();
|
||||||
|
XSetSelectionOwner(sdl_wminfo.info.x11.display, XA_CLIPBOARD, sdl_wminfo.info.x11.window, CurrentTime);
|
||||||
|
XFlush(sdl_wminfo.info.x11.display);
|
||||||
|
sdl_wminfo.info.x11.unlock_func();
|
||||||
#else
|
#else
|
||||||
printf("Not implemented: put text on clipboard \"%s\"\n", text);
|
printf("Not implemented: put text on clipboard \"%s\"\n", text);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user