clipboard - Retrieving Selection Data from Applications other than xterm -


i trying build xclient monitors clipboard selections, namely primary selection. attached code, selections running xterm windows being retrieved satisfactorily. retrieving selections other applications never working. not understand why. can offer advise?

(to compile use gcc -l/usr/x11r6/lib -lx11 [filename.cpp])

#include <x11/xlib.h> #include <x11/xutil.h> #include <x11/xatom.h> #include <assert.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h>  char chr_title[] = { "com clipboard xclient" };  int main(int argc, char *argv[]) {      /*declarations */     display *ads_display;     window ds_window;     gc ds_gc;     xevent ds_event;     xsizehints ds_size_hints;     xwmhints ds_wm_hints;     int iml_screen;     unsigned long ull_foreground, ull_background;     int iml_i;     char chr_text[10];     int iml_done;     atom ds_property;      /*initialisation*/      ads_display = xopendisplay(null);      assert(ads_display); //null pointer check      iml_screen = defaultscreen(ads_display);      /* default pixel values */     ull_background = whitepixel(ads_display, iml_screen);     ull_foreground = blackpixel(ads_display, iml_screen);      /* default program-specified window position , size */     ds_size_hints.x = 200;     ds_size_hints.y = 300;      ds_size_hints.width = 350;     ds_size_hints.height = 250;      ds_size_hints.flags = pposition | psize;      ds_wm_hints.flags = inputhint;     ds_wm_hints.input = true;      fprintf(stderr, "\ncreating simple window");     ds_window = xcreatesimplewindow(ads_display,         defaultrootwindow(ads_display), ds_size_hints.x, ds_size_hints.y,         ds_size_hints.width, ds_size_hints.height, 5, ull_foreground,         ull_background);      xsetstandardproperties(ads_display, ds_window, chr_title, chr_title, none,         argv, argc, &ds_size_hints);      xsetwmhints(ads_display, ds_window, &ds_wm_hints);      /* gc creation , initialisation */     ds_gc = xcreategc(ads_display, ds_window, 0, 0);     xsetbackground(ads_display, ds_gc, ull_background);     xsetforeground(ads_display, ds_gc, ull_foreground);      /* input event selection */     xselectinput(ads_display, ds_window, buttonpressmask | keypressmask         | exposuremask | propertychangemask);      /* window mapping */     xmapraised(ads_display, ds_window);      /*main event-reading loop */     iml_done = 0;      while (iml_done == 0) {         /* read next event */         xnextevent(ads_display, &ds_event);         switch (ds_event.type) {          /* repaint window on expose events */         case expose:         if (ds_event.xexpose.count == 0) {             xdrawimagestring(ds_event.xexpose.display,                 ds_event.xexpose.window, ds_gc, 50, 50, chr_title,                 strlen(chr_title));         }         break;          /* process mouse-button presses */         case buttonpress:             fprintf(stderr, "\ncalling xconvertselection()...");         xconvertselection(ads_display, xa_primary, xa_string, none,         ds_window, ds_event.xbutton.time);          xflush(ads_display);         break;          case selectionnotify:          fprintf(stderr, "\nselection notify event:");          atom type;         int format, result;         unsigned long len, bytes_left, dummy;         unsigned char *data;          result = xgetwindowproperty(ads_display, ds_window, xa_string, 0, 0, //off, len                 0, // delete 0==false                 anypropertytype, //flag                 &type, // return type                 &format, // return format                 &len, &bytes_left, //that                 &data);         fprintf(stderr, "\nreturn xgetwindowproperty(): %d.", result);          fprintf(stderr, "\ntype:%i len:%lu format:%i byte_left:%lu",                 (int) type, len, format, bytes_left);          // data there         if (bytes_left > 0) {             result = xgetwindowproperty(ads_display, ds_window, xa_string,                 0, bytes_left, 0, anypropertytype, &type, &format,                 &len, &dummy, &data);             if (result == success)                 fprintf(stderr, "\ndata:\n%s\n", data);             else                 fprintf(stderr, "\nfail\n");              xfree(data);          } //end if (bytes_left > 0)         break;         }// end switch (ds_event.type)      } /* while (done == 0) */      /* termination */     xfreegc(ads_display, ds_gc);     xdestroywindow(ads_display, ds_window);     xclosedisplay(ads_display);     exit(0); } 

try printing out selectionnotify event fields, maybe property in there none because selection doesn't exist or isn't in string format? maybe clicking on window causes focus out , apps drop primary then?

how x11 clipboard handle multiple data formats? may useful snippet of python inspect available selections.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -