Introduction
Introduction Statistics Contact Development Disclaimer Help
tselection code cleanup. - st - [fork] customized build of st, the simple termi…
git clone git://src.adamsgaard.dk/st
Log
Files
Refs
README
LICENSE
---
commit d581bfccd7c2987e12809383d8ce1f833529b715
parent b1e6099220f7e10d88adb8d960db27f63f1d8ccb
Author: AurĂ©lien Aptel <[email protected]>
Date: Mon, 8 Nov 2010 19:49:13 +0100
selection code cleanup.
Diffstat:
M st.c | 97 ++++++++---------------------…
1 file changed, 24 insertions(+), 73 deletions(-)
---
diff --git a/st.c b/st.c
t@@ -286,35 +286,24 @@ static char *getseltext() {
static void selection_notify(XEvent *e) {
unsigned long nitems;
- unsigned long length;
- int format, res;
+ unsigned long ofs, rem;
+ int format;
unsigned char *data;
Atom type;
- res = XGetWindowProperty(xw.dis, xw.win, XA_PRIMARY, 0, 0, False,
- AnyPropertyType, &type, &format, &nitems, &len…
- switch(res) {
- case BadAtom:
- case BadValue:
- case BadWindow:
- fprintf(stderr, "Invalid paste, XGetWindowProperty0");
+ ofs = 0;
+ do {
+ if(XGetWindowProperty(xw.dis, xw.win, XA_PRIMARY, ofs, BUFSIZ/…
+ False, AnyPropertyType, &type, &format,
+ &nitems, &rem, &data)) {
+ fprintf(stderr, "Clipboard allocation failed\n");
return;
- }
-
- res = XGetWindowProperty(xw.dis, xw.win, XA_PRIMARY, 0, length, False,
- AnyPropertyType, &type, &format, &nitems, &len…
- switch(res) {
- case BadAtom:
- case BadValue:
- case BadWindow:
- fprintf(stderr, "Invalid paste, XGetWindowProperty0");
- return;
- }
-
- if(data) {
+ }
ttywrite((const char *) data, nitems * format / 8);
XFree(data);
- }
+ /* number of 32-bit chunks returned */
+ ofs += nitems * format / 32;
+ } while(rem > 0);
}
static void selpaste() {
t@@ -325,7 +314,6 @@ static void selection_request(XEvent *e)
{
XSelectionRequestEvent *xsre;
XSelectionEvent xev;
- int res;
Atom xa_targets;
xsre = (XSelectionRequestEvent *) e;
t@@ -341,70 +329,33 @@ static void selection_request(XEvent *e)
if(xsre->target == xa_targets) {
/* respond with the supported type */
Atom string = XA_STRING;
- res = XChangeProperty(xsre->display, xsre->requestor, xsre->pr…
- PropModeReplace, (unsigned char *) &string, 1);
- switch(res) {
- case BadAlloc:
- case BadAtom:
- case BadMatch:
- case BadValue:
- case BadWindow:
- fprintf(stderr, "Error in selection_request, T…
- break;
- default:
- xev.property = xsre->property;
- }
+ XChangeProperty(xsre->display, xsre->requestor, xsre->property,
+ XA_ATOM, 32, PropModeReplace,
+ (unsigned char *) &string, 1);
+ xev.property = xsre->property;
} else if(xsre->target == XA_STRING) {
- res = XChangeProperty(xsre->display, xsre->requestor, xsre->pr…
- xsre->target, 8, PropModeReplace, (unsigned ch…
- strlen(sel.clip));
- switch(res) {
- case BadAlloc:
- case BadAtom:
- case BadMatch:
- case BadValue:
- case BadWindow:
- fprintf(stderr, "Error in selection_request, X…
- break;
- default:
- xev.property = xsre->property;
- }
+ XChangeProperty(xsre->display, xsre->requestor, xsre->property,
+ xsre->target, 8, PropModeReplace,
+ (unsigned char *) sel.clip, strlen(sel.clip));
+ xev.property = xsre->property;
}
/* all done, send a notification to the listener */
- res = XSendEvent(xsre->display, xsre->requestor, True, 0, (XEvent *) &…
- switch(res) {
- case 0:
- case BadValue:
- case BadWindow:
- fprintf(stderr, "Error in selection_requested, XSendEv…
- }
+ if(!XSendEvent(xsre->display, xsre->requestor, True, 0, (XEvent *) &xe…
+ fprintf(stderr, "Error sending SelectionNotify event\n");
}
static void selcopy(char *str) {
/* register the selection for both the clipboard and the primary */
Atom clipboard;
- int res;
free(sel.clip);
sel.clip = str;
- res = XSetSelectionOwner(xw.dis, XA_PRIMARY, xw.win, CurrentTime);
- switch(res) {
- case BadAtom:
- case BadWindow:
- fprintf(stderr, "Invalid copy, XSetSelectionOwner");
- return;
- }
+ XSetSelectionOwner(xw.dis, XA_PRIMARY, xw.win, CurrentTime);
clipboard = XInternAtom(xw.dis, "CLIPBOARD", 0);
- res = XSetSelectionOwner(xw.dis, clipboard, xw.win, CurrentTime);
- switch(res) {
- case BadAtom:
- case BadWindow:
- fprintf(stderr, "Invalid copy, XSetSelectionOwner");
- return;
- }
+ XSetSelectionOwner(xw.dis, clipboard, xw.win, CurrentTime);
XFlush(xw.dis);
}
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.