I wonder if it is possible to get co-ordinates of the cursor position outside the ApplicationWindow in Gtk4 with gjs? It seems it is possible in Gtk3 but after grabbing the device like in this example. To the best of my knowledge that API has been removed in Gtk4. How do I create something similar in Gtk4.
I can get co-ordinates of the cursor but relative to the ApplicationWindow.
I donât believe thatâs possible. You may be able to get the monitor or display geometry from GDK, but itâs generally considered ânot an applicationâs businessâ what happens outside of itself. I think the same principle applies to applications that want to move their own windows.
What is your end-goal for finding the pointer location on the screen?
I want to do what this color picker app is doing. I think it gets cursor coordinates on the screen, captures a screenshot of the screen at that particular coordinates and picks the RGB color values from the screenshot. I think the most common name used for such apps is eye dropper.
It is similar to the eye dropper browser addon. Except that the eye dropper addon is limited to the browser only. I was thinking of something similar but for the desktop. The linked desktop app picks color from anywhere including the browser. I could use the existing app but I want additional functionality like mapping the picked color to CSS library class out of the box.
Thanks. Looks like Xdp is part of the libportal library but I get an error when I try to import it like most of the APIs I have encountered in the gjs guide.
import Xdp from "gi://Xdp?version=1.0";
The above import gives me the error below.
JS ERROR: Error: Requiring Xdp, version 1.0: Typelib file for namespace âXdpâ, version â1.0â not found
Going by the error above, I guess I need to perhaps install libportal. However, the libportal docs doesnât exactly describe how. So how do I start using Xdp?
I donât know whether there is something I am supposed to do besides adding the libportal module to the manifest. I keep getting the same error even if I copied the linked code.
JS ERROR: Error: Requiring Xdp, version none: Typelib file for namespace âXdpâ (any version) not found
require@resource:///org/gnome/gjs/modules/esm/gi.js:16:28 @gi://Xdp:3:25
Take a look at GJS app that use libportal and do exactly what they do until you figure out whatâs the significant difference. Also, try âRebuildâ in GNOME Builder
Unless you share your code repo, I canât help you further.
Apparently the specified dependencies are not being downloaded if I go by the terminal logs. But when I clone the Workbench repo, it installs and runs fine. Though, I still see some errors while building Workbench, theyâre not related to libportal.
I have created a GitHub repo if you want to take a look. Not really sure where the issue is. Libportal demo app
If anyone comes across this thread, apparently, I was getting that error because the libportal package is not being installed. Essentially when adding modules to the manifest, all modules must be added before the application module. In my case, I added the libportal module after the application module.
It seems the modules in the manifest are installed in order of appearance from the first. The installation stops when the application module is installed hence ignoring modules that come after. The Flatpak docs seems to miss that very important piece of information.