summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2013-04-29 14:12:15 +0200
committerRobin Watts <robin.watts@artifex.com>2013-04-29 13:23:58 +0100
commite1098d867424a700bc55899926020f7e446a2145 (patch)
tree33d68a778276d170507e86c4614037753bd1102c /apps
parent6f8c47f638e92d1824fcd2e5b57abfb5efd7171a (diff)
downloadmupdf-e1098d867424a700bc55899926020f7e446a2145.tar.xz
x11: Copy to clipboard on Ctl+C.
For better interoperability with non-unix-y apps that don't know about selection and middle-click paste, add the ability to use Ctl+C to copy the selected text to the clipboard. Thanks to Sebras for original patch.
Diffstat (limited to 'apps')
-rw-r--r--apps/x11_main.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/apps/x11_main.c b/apps/x11_main.c
index 987e3594..1c0ca0b0 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -63,6 +63,7 @@ void windrawstringxor(pdfapp_t *app, int x, int y, char *s);
void cleanup(pdfapp_t *app);
static Display *xdpy;
+static Atom XA_CLIPBOARD;
static Atom XA_TARGETS;
static Atom XA_TIMESTAMP;
static Atom XA_UTF8_STRING;
@@ -174,6 +175,7 @@ static void winopen(void)
if (!xdpy)
fz_throw(gapp.ctx, "cannot open display");
+ XA_CLIPBOARD = XInternAtom(xdpy, "CLIPBOARD", False);
XA_TARGETS = XInternAtom(xdpy, "TARGETS", False);
XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False);
XA_UTF8_STRING = XInternAtom(xdpy, "UTF8_STRING", False);
@@ -552,7 +554,7 @@ void windrawstring(pdfapp_t *app, int x, int y, char *s)
XDrawString(xdpy, xwin, xgc, x, y, s, strlen(s));
}
-void windocopy(pdfapp_t *app)
+void docopy(pdfapp_t *app, Atom copy_target)
{
unsigned short copyucs2[16 * 1024];
char *latin1 = copylatin1;
@@ -577,11 +579,16 @@ void windocopy(pdfapp_t *app)
*utf8 = 0;
*latin1 = 0;
- XSetSelectionOwner(xdpy, XA_PRIMARY, xwin, copytime);
+ XSetSelectionOwner(xdpy, copy_target, xwin, copytime);
justcopied = 1;
}
+void windocopy(pdfapp_t *app)
+{
+ docopy(app, XA_PRIMARY);
+}
+
void onselreq(Window requestor, Atom selection, Atom target, Atom property, Time time)
{
XEvent nevt;
@@ -835,7 +842,9 @@ int main(int argc, char **argv)
len = 1; buf[0] = '.';
break;
}
- if (len)
+ if (xevt.xkey.state & ControlMask && keysym == XK_c)
+ docopy(&gapp, XA_CLIPBOARD);
+ else if (len)
onkey(buf[0]);
onmouse(oldx, oldy, 0, 0, 0);