Clear specific X buffer directly, without going through xsel or xclip

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to completely disable middle-click for pasting from a buffer, using Radivarig's solution.




Place this in ~/.xbindkeysrc



"echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
b:2 + Release



This solution, however, depends on xsel (or, equivalently, xclip) completing its job quickly.



Recently I've noticed a delay of several seconds for xsel and xclip when attempting to clear the primary buffer.



Is there a less "polite" way than whatever xsel or xclip are doing to force X to empty a specific buffer?



The Linux distribution in question is Manjaro ... this could be a Manjaro or Arch-specific bug, but end-user-oriented information about how to interact with the X11 server without xsel or xclip or another similar tool seems to be somewhat lacking.



~ > xclip -selection primary -verbose -in </dev/null
Connected to X server.
Using selection: XA_PRIMARY
Using UTF8_STRING.
Waiting for selection requests, Control-C to quit
Waiting for selection request number 1
Waiting for selection request number 2
Time: 13s

~ > xclip -selection primary -verbose -in </dev/null
...
Time: 11s

~ > xclip -selection primary -verbose -in </dev/null
...
Time: 23s


I attached gdb to one of the hung xclips and it appears to be stuck waiting for a response from the X server.



(gdb) where
#0 0x00007f905e1f1b78 in poll () from /usr/lib/libc.so.6
#1 0x00007f905dc68630 in ?? () from /usr/lib/libxcb.so.1
#2 0x00007f905dc6a2db in xcb_wait_for_event () from /usr/lib/libxcb.so.1
#3 0x00007f905e306009 in _XReadEvents () from /usr/lib/libX11.so.6
#4 0x00007f905e2f4ee1 in XNextEvent () from /usr/lib/libX11.so.6
#5 0x0000563eb8eaea70 in ?? ()
#6 0x00007f905e125223 in __libc_start_main () from /usr/lib/libc.so.6
#7 0x0000563eb8eaf53e in ?? ()


I attempted to write a stripped down program using the X API directly, based on part of the xsel source code, in particular: https://github.com/kfish/xsel/blob/master/xsel.c#L1003-L1018 .



In order to clear the buffer, xsel appears to be relying on this property of XSetSelectionOwner:




If the new owner (whether a client or None ) is not the same as the
current owner of the selection and the current owner is not None , the
current owner is sent a SelectionClear event. If the client that is
the owner of a selection is later terminated (that is, its connection
is closed) or if the owner window it has specified in the request is
later destroyed, the owner of the selection automatically reverts to
None , but the last-change time is not affected. The selection atom is
uninterpreted by the X server. XGetSelectionOwner() returns the owner
window, which is reported in SelectionRequest and SelectionClear
events. Selections are global to the X server.




Here's my attempt to strip down xsel to just the functionality I need.



I'm assuming that the owner of the XA_PRIMARY buffer usually isn't None. I am setting it to None inside the body of my C program and then hoping it worked.



// clear.c
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <assert.h>

// always debug
#undef NDEBUG

static Display * display = NULL;

static char * display_name = NULL;

static void clear_selection(void)

printf("%dn", 300);
display = XOpenDisplay(display_name);
assert(display != NULL);
printf("%dn", 200);
XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
printf("%dn, 500);
XSync(display, False);
return;


int main(void)

printf("%dn", 100);
clear_selection();
printf("%dn", 200);
return 0;



This program runs and prints



100
300
400
500
200


as expected.



However, it failed to clear the primary buffer.



xclip -selection -primary out shows the same thing before and after.









share

























    up vote
    0
    down vote

    favorite












    I am trying to completely disable middle-click for pasting from a buffer, using Radivarig's solution.




    Place this in ~/.xbindkeysrc



    "echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
    b:2 + Release



    This solution, however, depends on xsel (or, equivalently, xclip) completing its job quickly.



    Recently I've noticed a delay of several seconds for xsel and xclip when attempting to clear the primary buffer.



    Is there a less "polite" way than whatever xsel or xclip are doing to force X to empty a specific buffer?



    The Linux distribution in question is Manjaro ... this could be a Manjaro or Arch-specific bug, but end-user-oriented information about how to interact with the X11 server without xsel or xclip or another similar tool seems to be somewhat lacking.



    ~ > xclip -selection primary -verbose -in </dev/null
    Connected to X server.
    Using selection: XA_PRIMARY
    Using UTF8_STRING.
    Waiting for selection requests, Control-C to quit
    Waiting for selection request number 1
    Waiting for selection request number 2
    Time: 13s

    ~ > xclip -selection primary -verbose -in </dev/null
    ...
    Time: 11s

    ~ > xclip -selection primary -verbose -in </dev/null
    ...
    Time: 23s


    I attached gdb to one of the hung xclips and it appears to be stuck waiting for a response from the X server.



    (gdb) where
    #0 0x00007f905e1f1b78 in poll () from /usr/lib/libc.so.6
    #1 0x00007f905dc68630 in ?? () from /usr/lib/libxcb.so.1
    #2 0x00007f905dc6a2db in xcb_wait_for_event () from /usr/lib/libxcb.so.1
    #3 0x00007f905e306009 in _XReadEvents () from /usr/lib/libX11.so.6
    #4 0x00007f905e2f4ee1 in XNextEvent () from /usr/lib/libX11.so.6
    #5 0x0000563eb8eaea70 in ?? ()
    #6 0x00007f905e125223 in __libc_start_main () from /usr/lib/libc.so.6
    #7 0x0000563eb8eaf53e in ?? ()


    I attempted to write a stripped down program using the X API directly, based on part of the xsel source code, in particular: https://github.com/kfish/xsel/blob/master/xsel.c#L1003-L1018 .



    In order to clear the buffer, xsel appears to be relying on this property of XSetSelectionOwner:




    If the new owner (whether a client or None ) is not the same as the
    current owner of the selection and the current owner is not None , the
    current owner is sent a SelectionClear event. If the client that is
    the owner of a selection is later terminated (that is, its connection
    is closed) or if the owner window it has specified in the request is
    later destroyed, the owner of the selection automatically reverts to
    None , but the last-change time is not affected. The selection atom is
    uninterpreted by the X server. XGetSelectionOwner() returns the owner
    window, which is reported in SelectionRequest and SelectionClear
    events. Selections are global to the X server.




    Here's my attempt to strip down xsel to just the functionality I need.



    I'm assuming that the owner of the XA_PRIMARY buffer usually isn't None. I am setting it to None inside the body of my C program and then hoping it worked.



    // clear.c
    #include <stdio.h>
    #include <X11/Xlib.h>
    #include <X11/Xatom.h>
    #include <assert.h>

    // always debug
    #undef NDEBUG

    static Display * display = NULL;

    static char * display_name = NULL;

    static void clear_selection(void)

    printf("%dn", 300);
    display = XOpenDisplay(display_name);
    assert(display != NULL);
    printf("%dn", 200);
    XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
    printf("%dn, 500);
    XSync(display, False);
    return;


    int main(void)

    printf("%dn", 100);
    clear_selection();
    printf("%dn", 200);
    return 0;



    This program runs and prints



    100
    300
    400
    500
    200


    as expected.



    However, it failed to clear the primary buffer.



    xclip -selection -primary out shows the same thing before and after.









    share























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to completely disable middle-click for pasting from a buffer, using Radivarig's solution.




      Place this in ~/.xbindkeysrc



      "echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
      b:2 + Release



      This solution, however, depends on xsel (or, equivalently, xclip) completing its job quickly.



      Recently I've noticed a delay of several seconds for xsel and xclip when attempting to clear the primary buffer.



      Is there a less "polite" way than whatever xsel or xclip are doing to force X to empty a specific buffer?



      The Linux distribution in question is Manjaro ... this could be a Manjaro or Arch-specific bug, but end-user-oriented information about how to interact with the X11 server without xsel or xclip or another similar tool seems to be somewhat lacking.



      ~ > xclip -selection primary -verbose -in </dev/null
      Connected to X server.
      Using selection: XA_PRIMARY
      Using UTF8_STRING.
      Waiting for selection requests, Control-C to quit
      Waiting for selection request number 1
      Waiting for selection request number 2
      Time: 13s

      ~ > xclip -selection primary -verbose -in </dev/null
      ...
      Time: 11s

      ~ > xclip -selection primary -verbose -in </dev/null
      ...
      Time: 23s


      I attached gdb to one of the hung xclips and it appears to be stuck waiting for a response from the X server.



      (gdb) where
      #0 0x00007f905e1f1b78 in poll () from /usr/lib/libc.so.6
      #1 0x00007f905dc68630 in ?? () from /usr/lib/libxcb.so.1
      #2 0x00007f905dc6a2db in xcb_wait_for_event () from /usr/lib/libxcb.so.1
      #3 0x00007f905e306009 in _XReadEvents () from /usr/lib/libX11.so.6
      #4 0x00007f905e2f4ee1 in XNextEvent () from /usr/lib/libX11.so.6
      #5 0x0000563eb8eaea70 in ?? ()
      #6 0x00007f905e125223 in __libc_start_main () from /usr/lib/libc.so.6
      #7 0x0000563eb8eaf53e in ?? ()


      I attempted to write a stripped down program using the X API directly, based on part of the xsel source code, in particular: https://github.com/kfish/xsel/blob/master/xsel.c#L1003-L1018 .



      In order to clear the buffer, xsel appears to be relying on this property of XSetSelectionOwner:




      If the new owner (whether a client or None ) is not the same as the
      current owner of the selection and the current owner is not None , the
      current owner is sent a SelectionClear event. If the client that is
      the owner of a selection is later terminated (that is, its connection
      is closed) or if the owner window it has specified in the request is
      later destroyed, the owner of the selection automatically reverts to
      None , but the last-change time is not affected. The selection atom is
      uninterpreted by the X server. XGetSelectionOwner() returns the owner
      window, which is reported in SelectionRequest and SelectionClear
      events. Selections are global to the X server.




      Here's my attempt to strip down xsel to just the functionality I need.



      I'm assuming that the owner of the XA_PRIMARY buffer usually isn't None. I am setting it to None inside the body of my C program and then hoping it worked.



      // clear.c
      #include <stdio.h>
      #include <X11/Xlib.h>
      #include <X11/Xatom.h>
      #include <assert.h>

      // always debug
      #undef NDEBUG

      static Display * display = NULL;

      static char * display_name = NULL;

      static void clear_selection(void)

      printf("%dn", 300);
      display = XOpenDisplay(display_name);
      assert(display != NULL);
      printf("%dn", 200);
      XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
      printf("%dn, 500);
      XSync(display, False);
      return;


      int main(void)

      printf("%dn", 100);
      clear_selection();
      printf("%dn", 200);
      return 0;



      This program runs and prints



      100
      300
      400
      500
      200


      as expected.



      However, it failed to clear the primary buffer.



      xclip -selection -primary out shows the same thing before and after.









      share













      I am trying to completely disable middle-click for pasting from a buffer, using Radivarig's solution.




      Place this in ~/.xbindkeysrc



      "echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
      b:2 + Release



      This solution, however, depends on xsel (or, equivalently, xclip) completing its job quickly.



      Recently I've noticed a delay of several seconds for xsel and xclip when attempting to clear the primary buffer.



      Is there a less "polite" way than whatever xsel or xclip are doing to force X to empty a specific buffer?



      The Linux distribution in question is Manjaro ... this could be a Manjaro or Arch-specific bug, but end-user-oriented information about how to interact with the X11 server without xsel or xclip or another similar tool seems to be somewhat lacking.



      ~ > xclip -selection primary -verbose -in </dev/null
      Connected to X server.
      Using selection: XA_PRIMARY
      Using UTF8_STRING.
      Waiting for selection requests, Control-C to quit
      Waiting for selection request number 1
      Waiting for selection request number 2
      Time: 13s

      ~ > xclip -selection primary -verbose -in </dev/null
      ...
      Time: 11s

      ~ > xclip -selection primary -verbose -in </dev/null
      ...
      Time: 23s


      I attached gdb to one of the hung xclips and it appears to be stuck waiting for a response from the X server.



      (gdb) where
      #0 0x00007f905e1f1b78 in poll () from /usr/lib/libc.so.6
      #1 0x00007f905dc68630 in ?? () from /usr/lib/libxcb.so.1
      #2 0x00007f905dc6a2db in xcb_wait_for_event () from /usr/lib/libxcb.so.1
      #3 0x00007f905e306009 in _XReadEvents () from /usr/lib/libX11.so.6
      #4 0x00007f905e2f4ee1 in XNextEvent () from /usr/lib/libX11.so.6
      #5 0x0000563eb8eaea70 in ?? ()
      #6 0x00007f905e125223 in __libc_start_main () from /usr/lib/libc.so.6
      #7 0x0000563eb8eaf53e in ?? ()


      I attempted to write a stripped down program using the X API directly, based on part of the xsel source code, in particular: https://github.com/kfish/xsel/blob/master/xsel.c#L1003-L1018 .



      In order to clear the buffer, xsel appears to be relying on this property of XSetSelectionOwner:




      If the new owner (whether a client or None ) is not the same as the
      current owner of the selection and the current owner is not None , the
      current owner is sent a SelectionClear event. If the client that is
      the owner of a selection is later terminated (that is, its connection
      is closed) or if the owner window it has specified in the request is
      later destroyed, the owner of the selection automatically reverts to
      None , but the last-change time is not affected. The selection atom is
      uninterpreted by the X server. XGetSelectionOwner() returns the owner
      window, which is reported in SelectionRequest and SelectionClear
      events. Selections are global to the X server.




      Here's my attempt to strip down xsel to just the functionality I need.



      I'm assuming that the owner of the XA_PRIMARY buffer usually isn't None. I am setting it to None inside the body of my C program and then hoping it worked.



      // clear.c
      #include <stdio.h>
      #include <X11/Xlib.h>
      #include <X11/Xatom.h>
      #include <assert.h>

      // always debug
      #undef NDEBUG

      static Display * display = NULL;

      static char * display_name = NULL;

      static void clear_selection(void)

      printf("%dn", 300);
      display = XOpenDisplay(display_name);
      assert(display != NULL);
      printf("%dn", 200);
      XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
      printf("%dn, 500);
      XSync(display, False);
      return;


      int main(void)

      printf("%dn", 100);
      clear_selection();
      printf("%dn", 200);
      return 0;



      This program runs and prints



      100
      300
      400
      500
      200


      as expected.



      However, it failed to clear the primary buffer.



      xclip -selection -primary out shows the same thing before and after.







      x11 x





      share












      share










      share



      share










      asked 5 mins ago









      Gregory Nisbet

      1,232918




      1,232918

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475906%2fclear-specific-x-buffer-directly-without-going-through-xsel-or-xclip%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475906%2fclear-specific-x-buffer-directly-without-going-through-xsel-or-xclip%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay