rcaelers / workrave

Workrave is a program that assists in the recovery and prevention of Repetitive Strain Injury (RSI). The program frequently alerts you to take micro-pauses, rest breaks and restricts you to your daily limit.
https://www.workrave.org
GNU General Public License v3.0
1.61k stars 204 forks source link

Workrave Wayland support (meta) #523

Open ValdikSS opened 10 months ago

ValdikSS commented 10 months ago

Describe the bug

Right now Workrave 1.10.52 has limited support for different Linux Wayland DEs/compositors other than Gnome's Mutter:

  1. Crash on start with segmentation fault unless started with environment variable: #522, #212, #302
  2. Inability to monitor for keyboard/mouse activity on non-Gnome (non-Mutter) compositors: no implementation for kde-idle or idle-notify Wayland protocols
  3. Incorrect position of nag bar and rest break window: seem fixed for Mutter in #163, still the issue for KDE Kwin.
rcaelers commented 10 months ago

I fixed the crash, and have just implemented monitoring using the idle-notify protocol. Current checking that this did not break anything. This will appear in the next 1.11 beta release. If stable, I will try to backport it to 1.10. I haven't checked the incorrect position yet.

ValdikSS commented 10 months ago

Current fix for segmentation fault on start:

Screenshot_20240116_224256-fs8

ValdikSS commented 10 months ago

I fixed the crash, and have just implemented monitoring using the idle-notify protocol. Current checking that this did not break anything.

Thanks, I saw it several hours ago in main, and now I see Idle which you've pushed 30 minutes ago :D

Here's my hack written in Python, which uses Workrave DBus interface to update the activity for now.

workrave_wayland_idle_kick.tar.gz

gringus commented 9 months ago

Would it be possible to make Wayland support configurable (eg. -DWITH_WAYLAND=OFF)? Currently, it's not possible to build it without Wayland (on a non-Wayland system).

wolftune commented 8 months ago

got bit by this tonight, KDE Neon moved to KDE 6 and Wayland, workrave stopped working right, and even with environment, it thinks I'm inactive when I'm actually active.

I think it needs to use kde-idle or something

jjramsey commented 7 months ago

I've tried out the latest Workrave (1.11.0_beta.12.0.g7cab420-1) on two different wlroots-based compositors, LabWC and Sway, and got the same results both times: a segfault that, if it leaves behind a $HOME/.cache/workrave/workrave.log file, leaves behind an empty one. My wlroots version is 0.17.2.

On GNOME 46, Workrave works fine so far. I've unchecked the "Force use of X11 on Wayland" option.

ETA: Here's a backtrace from GDB:

0  UnixInputMonitorFactory::create_monitor (this=0x5555557dc740, capability=<optimized out>) at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:1665
#1  0x000055555567871e in workrave::input_monitor::InputMonitorFactory::create_monitor (capability=workrave::input_monitor::MonitorCapability::Activity)
    at /usr/src/debug/workrave-git/workrave/libs/input-monitor/src/InputMonitorFactory.cc:61
#2  LocalActivityMonitor::LocalActivityMonitor (this=0x55555582c5b0) at /usr/src/debug/workrave-git/workrave/libs/core/src/LocalActivityMonitor.cc:42
#3  std::_Construct<LocalActivityMonitor> (__p=0x55555582c5b0) at /usr/include/c++/13.2.1/bits/stl_construct.h:119
#4  std::allocator_traits<std::allocator<void> >::construct<LocalActivityMonitor> (__p=0x55555582c5b0) at /usr/include/c++/13.2.1/bits/alloc_traits.h:660
#5  std::_Sp_counted_ptr_inplace<LocalActivityMonitor, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<>(std::allocator<void>) (__a=..., this=0x55555582c5a0)
    at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:604
#6  std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<LocalActivityMonitor, std::allocator<void>>(LocalActivityMonitor*&, std::_Sp_alloc_shared_tag<std::allocator<void> >)
    (__a=..., __p=<optimized out>, this=<optimized out>) at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:971
#7  std::__shared_ptr<LocalActivityMonitor, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>>(std::_Sp_alloc_shared_tag<std::allocator<void> >) (__tag=..., this=<optimized out>)
    at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:1712
#8  std::shared_ptr<LocalActivityMonitor>::shared_ptr<std::allocator<void>>(std::_Sp_alloc_shared_tag<std::allocator<void> >) (__tag=..., this=<optimized out>) at /usr/include/c++/13.2.1/bits/shared_ptr.h:464
#9  std::make_shared<LocalActivityMonitor> () at /usr/include/c++/13.2.1/bits/shared_ptr.h:1010
#10 Core::init_monitor (this=0x555555836dd0, display_name=<optimized out>) at /usr/src/debug/workrave-git/workrave/libs/core/src/Core.cc:184
#11 0x000055555567a09a in Core::init (this=this@entry=0x555555836dd0, argc=<optimized out>, argv=<optimized out>, app=app@entry=0x5555557a2540, display_name=0x7fffffffedd4 "wayland-0")
    at /usr/src/debug/workrave-git/workrave/libs/core/src/Core.cc:136
#12 0x00005555555eb69c in Application::init_core (this=0x5555557a2540) at /usr/src/debug/workrave-git/workrave/ui/app/Application.cc:261
#13 0x00005555555ddc18 in Application::main (this=this@entry=0x5555557a2540) at /usr/src/debug/workrave-git/workrave/ui/app/Application.cc:97
#14 0x00005555555e038f in run (argv=<optimized out>, argc=1) at /usr/src/debug/workrave-git/workrave/ui/app/main.cc:118
#15 main (argc=1, argv=<optimized out>) at /usr/src/debug/workrave-git/workrave/ui/app/main.cc:128
jjramsey commented 7 months ago

I recompiled Workrave with CMAKE_BUILD_TYPE set to debug and tested it in a labwc session again. Here's what I got:

gdb /usr/bin/workrave 
GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/workrave...
Reading symbols from /usr/lib/debug/usr/bin/workrave.debug...
(gdb) r
Starting program: /usr/bin/workrave 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[2024-04-04 16:50:30.776] [workrave] [info ] Workrave started
[2024-04-04 16:50:30.776] [workrave] [info ] Log file: /home/jjramsey/.cache/workrave/workrave.log
[New Thread 0x7ffff25ff6c0 (LWP 12221)]
[New Thread 0x7ffff1dfe6c0 (LWP 12222)]
[New Thread 0x7ffff15fd6c0 (LWP 12223)]
[New Thread 0x7ffff0dfc6c0 (LWP 12224)]
[New Thread 0x7fffe3fff6c0 (LWP 12225)]

Thread 1 "workrave" received signal SIGSEGV, Segmentation fault.
0x0000555555820a71 in UnixInputMonitorFactory::create_monitor (this=0x555555ac1140, 
    capability=workrave::input_monitor::MonitorCapability::Activity)
    at /usr/src/debug/workrave-git/workrave/libs/input-monitor/src/unix/UnixInputMonitorFactory.cc:124
124           initialized = monitor->init();
(gdb) bt
#0  0x0000555555820a71 in UnixInputMonitorFactory::create_monitor
    (this=0x555555ac1140, capability=workrave::input_monitor::MonitorCapability::Activity)
    at /usr/src/debug/workrave-git/workrave/libs/input-monitor/src/unix/UnixInputMonitorFactory.cc:124
#1  0x0000555555820418 in workrave::input_monitor::InputMonitorFactory::create_monitor
    (capability=workrave::input_monitor::MonitorCapability::Activity)
    at /usr/src/debug/workrave-git/workrave/libs/input-monitor/src/InputMonitorFactory.cc:61
#2  0x0000555555618f7a in LocalActivityMonitor::LocalActivityMonitor (this=0x555555adfa30, this=<optimized out>)
    at /usr/src/debug/workrave-git/workrave/libs/core/src/LocalActivityMonitor.cc:42
#3  0x0000555555799fd0 in std::_Construct<LocalActivityMonitor> (__p=0x555555adfa30)
    at /usr/include/c++/13.2.1/bits/stl_construct.h:119
#4  0x0000555555611cb1 in std::allocator_traits<std::allocator<void> >::construct<LocalActivityMonitor> (__p=0x555555adfa30)
    at /usr/include/c++/13.2.1/bits/alloc_traits.h:660
#5  std::_Sp_counted_ptr_inplace<LocalActivityMonitor, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<>(std::allocator<void>) (this=0x555555adfa20, __a=..., this=<optimized out>, __a=...)
    at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:604
#6  0x00005555556116eb in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<LocalActivityMonitor, std::allocator<void>>(LocalActivityMonitor*&, std::_Sp_alloc_shared_tag<std::allocator<void> >)
    (this=0x7fffffffe668, __p=@0x7fffffffe660: 0x0, __a=..., this=<optimized out>, __p=<optimized out>, __a=...)
    at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:971
#7  0x0000555555793b8a in std::__shared_ptr<LocalActivityMonitor, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>>(std::_Sp_alloc_shared_tag<std::allocator<void> >) (this=0x7fffffffe660, __tag=..., this=<optimized out>, __tag=...)
    at /usr/include/c++/13.2.1/bits/shared_ptr_base.h:1712
#8  0x0000555555610613 in std::shared_ptr<LocalActivityMonitor>::shared_ptr<std::allocator<void>>(std::_Sp_alloc_shared_tag<std::allocator<void> >) (this=0x7fffffffe660, __tag=..., this=<optimized out>, __tag=...)
    at /usr/include/c++/13.2.1/bits/shared_ptr.h:464
#9  0x0000555555790020 in std::make_shared<LocalActivityMonitor> () at /usr/include/c++/13.2.1/bits/shared_ptr.h:1010
#10 0x000055555578c120 in Core::init_monitor (this=0x555555ac17a0, display_name=0x7fffffffedd3 "wayland-0")
    at /usr/src/debug/workrave-git/workrave/libs/core/src/Core.cc:184
#11 0x000055555578bc6e in Core::init
--Type <RET> for more, q to quit, c to continue without paging--
    (this=0x555555ac17a0, argc=1, argv=0x7fffffffe958, app=0x555555a30540, display_name=0x7fffffffedd3 "wayland-0")
    at /usr/src/debug/workrave-git/workrave/libs/core/src/Core.cc:136
#12 0x0000555555640d05 in Application::init_core (this=0x555555a30540) at /usr/src/debug/workrave-git/workrave/ui/app/Application.cc:261
#13 0x000055555563fe05 in Application::main (this=0x555555a30540) at /usr/src/debug/workrave-git/workrave/ui/app/Application.cc:97
#14 0x000055555563839b in run (argc=1, argv=0x7fffffffe958) at /usr/src/debug/workrave-git/workrave/ui/app/main.cc:118
#15 0x0000555555638461 in main (argc=1, argv=0x7fffffffe958) at /usr/src/debug/workrave-git/workrave/ui/app/main.cc:128
(gdb) q
A debugging session is active.

    Inferior 1 [process 12218] will be killed.

Quit anyway? (y or n) y
jjramsey commented 7 months ago

I think I figured out the problem. Even though the CMake variable HAVE_MONITORS includes "wayland" as one of the monitors, Wayland support isn't fully built unless -DHAVE_WAYLAND:BOOL=TRUE is set when CMake is configuring the build.

I'm not sure, but I think what is happening is that in UnixInputMonitorFactory.cc, monitor_method is set to "wayland", but since HAVE_WAYLAND is undefined, the else if (monitor_method == "wayland") block is never executed, so the monitor variable is still nullptr when line 124, initialized = monitor->init();, is executed, hence the segfault.

ValdikSS commented 7 months ago

I can confirm the issue @jjramsey described (and the fix proposed). Additionally, on KDE I don't see the applet anymore. "Show fallback applet" works, but only when X11 session is forced.

The window still works, but no applet. The application overall works as well.

wolftune commented 7 months ago

@ValdikSS try the updated applet as described at https://github.com/wojnilowicz/workrave-applet/issues/12#issuecomment-2028829465

And if you have it working, maybe post at that issue to encourage the applet developer to formalize release of the KDE6 support

patch-work commented 6 months ago

Everything works on Fedora Linux 40, except timers and sound.

https://github.com/rcaelers/workrave/issues/543

jjramsey commented 5 months ago

Wayland not working under LabWC and Sway compositors: https://github.com/rcaelers/workrave/issues/550

andreas-hartmann commented 3 months ago

I'm still getting a segfault when using the version from the PPA on Plasma 6 Wayland unless I use GDK_BACKEND="x11" . Is all that's needed a new release on the PPA?

ValdikSS commented 1 month ago

@rcaelers current git master:

  1. Always forces X11 mode for some reason ([workrave] [info ] Forcing X11 backend), thus activity detection doesn't work
  2. Has seemingly broken dconf (settings are not saved, default settings for sound paths are not loaded

beta 13 used to work.