Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library features #37

Open
kqvanity opened this issue Aug 5, 2024 · 3 comments
Open

Library features #37

kqvanity opened this issue Aug 5, 2024 · 3 comments

Comments

@kqvanity
Copy link

kqvanity commented Aug 5, 2024

Hi,
I've been working on a java project that relies on system events e.g., text highlight cords, mouse click/release, etc.

I'm currently relying on this JNA sample, which allow me to

  • Execute callbacks whenever there's a text selection / text copied to clipboard
  • The selected/copied text is returned along the way

I was wondering if this library supports the following

  • Obtain the coordinates of the highlighted word
  • Register the aforementioned events i.e., text selection/highlighting (optional)
  • Obtain additional events such as mouse (single/double) click & clicked window (optional)

note: I mainly work with Android APIs using kotlin, but wanted to work on the JVM, so I'm completely unfamiliar with C++ concepts, X11 and how the windowing system works under Linux, so I'm sorry for my noob question.

Thanks

@moaxcp
Copy link
Owner

moaxcp commented Aug 6, 2024

Don't worry I am am still learning a lot about x11 as well. Yes I think this client could do these things. The difference is in x11-client the protocol is used directly. You have to look for the protocol structs that would be used in the x11lib functions to get the exact objects to use.

This can be done by looking at the x11lib code. But most of the function names will match the protocol class to use in this library. For instance SelectSelectionInput from the example.

@kqvanity
Copy link
Author

I've been trying to come up with a working example in C under bspwm, and only got mouse click events and selected text. Problem is that I can't figure out how to map it to the library APIs.

If obtaining selection metadata e.g., highlighted text, its cords isn't overly complex, could you please provide a minimal working example.

Also for some reason the library is only available from maven central up until v0.17.0

@moaxcp
Copy link
Owner

moaxcp commented Dec 30, 2024

I tried this out but got an error. RequestError(firstErrorOffset=0, sequenceNumber=37, badValue=0, minorOpcode=2, majorOpcode=-118) I think it is from the window id but I'm not sure.

public class XFixesSelection {
  public static void main(String... args) throws IOException {
    try (var client = X11Client.connect()) {
      var version = client.send(QueryVersion.builder().build());
      System.out.println(version);
      var extension = client.send(QueryExtension.builder()
          .name(toByteList("XFIXES"))
          .build());
      System.out.println(extension);
      var clipboard = client.getAtom("CLIPBOARD");
      System.out.println(clipboard);
      var primary = client.getAtom(Atom.PRIMARY.toString());
      System.out.println(primary);
      client.send(SelectSelectionInput.builder()
        .window(client.getDefaultRoot())
        .selection(clipboard.getId())
        .eventMaskEnable(SelectionEventMask.SET_SELECTION_OWNER)
        .build());
      client.sync();
      client.send(SelectSelectionInput.builder()
          .window(client.getDefaultRoot())
          .selection(primary.getId())
          .eventMaskEnable(SelectionEventMask.SET_SELECTION_OWNER)
          .build());
      while(true) {
        var event = client.getNextEvent();
        if (event instanceof SelectionNotifyEvent selection) {
          System.out.println(selection);
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants