-
-
Notifications
You must be signed in to change notification settings - Fork 639
Add mouse events for X11 #955
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
Conversation
The last commit isn't verified because I did several amends. (Should I squash all of them?) Regarding tests - I didn't see a point in writing them as CIs can't generate mouse events. I thoroughly tested added behaviour with Lua scripts so I know it works. Also wanted to mention that I added a lot of code for Lua table construction, but kept it in mouse_events.cc as it's only being used there so that it's excluded from conky. I'd be happy to add it to the rest of the code in llua.cc if that's prefered, but in that case, I'd like to extend it a tiny bit to support more types and make the table into its own object. I noticed Wayland support is being worked on. I'd be willing to implement the same functionality for Wayland too when it gets added. Holding off this PR until #664 is done might be a good idea. |
I know this is not an answer but you can use this project that allows you to use conky clicks https://github.com/netikras/ConkyClicky |
That makes it very hard to make "components" react to mouse clicks. I mean, you can store click info in a file and then read it form rendering calls, but that's complicating things a lot an slower due to file IO. Also, you'd have to manually map all components, this PR allows you to run a custom conky instance for buttons which makes click detection effortless in LUA. Mapping absolute mouse positions is a bad idea as you'll have to redo your job every time you change something in your layout. Another thing worth mentioning is, down the line, if this gets merged and the concept of components get added to conky, it would allow adding buttons without manual mapping or running them in separate instances. |
Test of Added mouse events to conky brndnmtthws#955
Since #664 has been merged in, you'll want to rebase this work. I tried to minimize the differences when moving code around, so you should be able to find the X11 stuff that was in Reading through your code I see some X structs passed around that shouldn't be, but we can clean that later with the rest anyway. |
I'll take a look at the diff to recall my changes. I think I'll start from scratch with prev code as reference. From what I remember, the only reason it took me as long as it did to implement was figuring out X11, lua bindings and conky code. I'll rebase sometime soon I hope. :) |
✅ Deploy Preview for conkyweb canceled.
|
Sorry, I separated changes onto another branch and fastforwarded master ytd so GitHub auto closed the PR. I'm almost done and will reopen this PR in a few days once I push to my fork. It was pretty straightforward to update the code. I also noticed that I might've caused issues with mouse events for root by mishandling some X events so I'd like to debug that. Thanks to mmuman's work I noticed ncurses and would like to check how conky interfaces with it to see whether adding mouse events to ncurses display would also make sense and be straightforward enough. |
Signed-off-by: Tin Svagelj <tin.svagelj@live.com>
Fixed a use after free error I previously introduced. Cleaned up Decided to forgo adding mouse events to ncurses for now. |
Signed-off-by: Tin Svagelj <tin.svagelj@live.com>
Because func was previously char* I forgot to update NORM_ERR function argument to `func.c_str()` not that it's std::string. Previously func was pointing to std::string memory that was freed at assignment. Signed-off-by: Tin Svagelj <tin.svagelj@live.com>
General description
This PR adds a
lua_mouse_hook
to Lua config script as suggested in issue #938. I remembered wanting click events in conky before, and I wanted them again, this time I understood C & C++ a bit more so I decided to implement it.Instead of defining 6 different hooks, I opted for creating just one and passing the relevant data in a table as an argument. Hopefully, this table stuff doesn't break any guidelines. This also means that
lua_mouse_hook
is not adjustable by context (can't pass custom arguments), but mouse action handling is generally very case-specific so that shouldn't be a problem.I added a custom build flag which means this can be turned off completely if not wanted. There is some code outside of #ifdef, but it will be optimized away by most compilers as it's very trivial (declaring a variable that never changes). I can wrap it if needed.
List of events handled by the
lua_mouse_hook
button_down
- called when a mouse button is clickedbutton_up
- called when a mouse button is releasedbutton_scroll
- called on scroll action (X handles it the same way as button clicks)mouse_move
- called when the pointer is being dragged across conky windowmouse_enter
- called when the pointer enters conky windowmouse_leave
- called when the pointer leaves conky windowUsers are supposed to handle the events by reading
event.type
string and putting logic into appropriate if-clauses - whereevent
is the name of the first (and only) function argument and value is one of the event names from the above list. If there is an error with code,event.type == "err"
.Users can return true to signal conky that the event has been "consumed" and shouldn't be passed to the root window. If nothing is returned, false is assumed which pushes the event through.
Depending on event type, different data is appended to the
event
table:Move event
event
table has following keys:x
- window-relative cursor x position (int)y
- window-relative cursor y position (int)x_abs
- display-relative cursor x position (int)y_abs
- display-relative cursor y position (int)time
- time in ms provided by Xlib (ulong)Button press and release event
event
table has all move event entries and additionally:mods
- table of buttons and modifier keys being held (name to bool map)shift
lock
control
mod1
num_lock
mod3
mod4
mod5
mouse_left
mouse_right
mouse_middle
scroll_up
scroll_down
button
- number of the button being pressed/released (int)Scroll event
Same as button press and release event but instead of the
button
field, adirection
field is provided, holding eitherup
ordown
string value - depending on scroll direction.Mouse enter/leave event
Called when the mouse enters or leaves conky window area. This might be useful for "turning off" "buttons" when the user drags their mouse outside the window while holding the mouse button pressed.
event
fields are the same as in the movement event.Problems
own_window_type
property is set todesktop
oroverride
, no mouse_events are being handled as making any changes to events root window listens to caused a crash while I was initially trying to get the code to work. This sadly means that users with some WMs/DEs won't be able to use mouse events at all (for instance me, bspwm). I also tested this on XFCE where all other mounting options worked fine (again, didn't modify the root window). On bspwm anything other than desktop and override make conky render as a window. Sudo didn't prevent crashing.Screenshots
Sadly I haven't gotten into Cairo yet, so all of these are pretty technical.
Imgur post containing images below.
Errors you see in VSCode navigation are because my environment isn't configured, wouldn't be able to compile and run it if they were actual errors.
Lua script using all provided options
I used this script for the above images. I fixed it a bit here because the 'mods' section had the wrong indentation for first item (extra '\t').
Notes
I have a few additional thoughts and concerns: