Sathvik-Rao / ClipCascade

ClipCascade is a lightweight utility that automatically syncs the clipboard across devices, no key press required.
GNU General Public License v3.0
430 stars 4 forks source link

App won't start on Wayland without X11 backend #12

Closed davebooi closed 1 month ago

davebooi commented 1 month ago

Description

App won't start on Wayland without X11 backend. Details as per below

Steps to Reproduce

  1. Install requirements as per README
  2. start via sudo python main.py
  3. Error as per below error message

Expected Behavior

App should start

Actual Behavior

App is crashing with an error message: `

sudo python3 main.py Authorization required, but no authorization protocol specified Authorization required, but no authorization protocol specified Authorization required, but no authorization protocol specified Authorization required, but no authorization protocol specified Traceback (most recent call last): File "/home/dave/git/ClipCascade/ClipCascade/main.py", line 22, in from gui.tray import TaskbarPanel File "/home/dave/git/ClipCascade/ClipCascade/gui/tray.py", line 2, in from pystray import Icon, MenuItem as item, Menu File "/usr/lib/python3.12/site-packages/pystray/init.py", line 64, in Icon = backend().Icon ^^^^^^^^^ File "/usr/lib/python3.12/site-packages/pystray/init.py", line 56, in backend return candidate() ^^^^^^^^^^^ File "/usr/lib/python3.12/site-packages/pystray/init.py", line 36, in xorg from . import _xorg as backend; return backend ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/site-packages/pystray/_xorg.py", line 36, in display = Xlib.display.Display() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/site-packages/Xlib/display.py", line 89, in init self.display = _BaseDisplay(display) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/site-packages/Xlib/display.py", line 71, in init protocol_display.Display.init(self, *args, **keys) File "/usr/lib/python3.12/site-packages/Xlib/protocol/display.py", line 166, in init raise error.DisplayConnectionError(self.display_name, r.reason) Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n' `

Environment

/label ~bug ~needs-investigation

Sathvik-Rao commented 1 month ago

Hi @davebooi

The current implementation supports only X11, as Wayland uses a different protocol for rendering GUI windows.

I will try to implement a terminal-based approach on Linux to avoid issues with GUIs.

I will update it in README

Sathvik-Rao commented 1 month ago

Hi @davebooi

Can you run it without using sudo?

python3 main.py

Sathvik-Rao commented 1 month ago

Hi @davebooi, Here are some potential solutions:

1. Use sudo with -E option

The -E option preserves the environment variables, including DISPLAY. Run your command like this:

sudo -E python3 main.py

2. Set the DISPLAY variable

Manually set the DISPLAY variable before running the script:

export DISPLAY=:0
sudo python3 main.py

3. Use xhost to allow access

Temporarily allow the root user access to the X server:

xhost +SI:localuser:root
sudo python3 main.py

After running your script, revoke the access:

xhost -SI:localuser:root

4. Run without sudo

If your script doesn't need elevated privileges, consider running it without sudo:

python3 main.py

5. Check for a .Xauthority file

Ensure that the .Xauthority file is correctly set up. Check its existence and permissions:

ls -l ~/.Xauthority

If it’s missing, you might need to regenerate it or make sure your user has access.

6. Use a virtual display

If you're running this on a headless server (no GUI), consider using a virtual display like Xvfb:

sudo apt-get install xvfb
Xvfb :1 -screen 0 1024x768x16 &
export DISPLAY=:1
python3 main.py
davebooi commented 1 month ago

Hi @davebooi

Can you run it without using sudo?

python3 main.py

nope, error is "no module named gi"

davebooi commented 1 month ago

Hi @davebooi, Here are some potential solutions:

1. Use sudo with -E option

The -E option preserves the environment variables, including DISPLAY. Run your command like this:

sudo -E python3 main.py

2. Set the DISPLAY variable

Manually set the DISPLAY variable before running the script:

export DISPLAY=:0
sudo python3 main.py

3. Use xhost to allow access

Temporarily allow the root user access to the X server:

xhost +SI:localuser:root
sudo python3 main.py

After running your script, revoke the access:

xhost -SI:localuser:root

4. Run without sudo

If your script doesn't need elevated privileges, consider running it without sudo:

python3 main.py

5. Check for a .Xauthority file

Ensure that the .Xauthority file is correctly set up. Check its existence and permissions:

ls -l ~/.Xauthority

If it’s missing, you might need to regenerate it or make sure your user has access.

6. Use a virtual display

If you're running this on a headless server (no GUI), consider using a virtual display like Xvfb:

sudo apt-get install xvfb
Xvfb :1 -screen 0 1024x768x16 &
export DISPLAY=:1
python3 main.py

Error message is the same with the E flag.

xfvb is not applicable (I think since I don't have any X11 componends in my setup

Sathvik-Rao commented 1 month ago

Most built-in modules rely on X11, which has been around since 1987. To implement support for Wayland, core modules need to be compatible with Wayland, as it was released later, in 2012. Therefore, the best option in my case is to build a terminal version specifically for Wayland users or to use Wayland GUI libraries. This is why Linux does not have a single executable that can run on all systems.

Sathvik-Rao commented 1 month ago

I will be developing a terminal-based version and will announce it soon.

Thank you!

Sathvik-Rao commented 1 month ago

Hi @davebooi

I am happy to announce that a terminal/non-GUI-based implementation has been released. see here

Thank you!

davebooi commented 1 month ago

Thank you so much for the update, appreciate it! Just tested the new version. Using a reverse proxy setup.

This is the error message I get upon starting the terminal version image

Server is running in a cloudflare tunnel, reverse proxy setting is used as per screenshot. I can connect to the server just fine from android as well as the linux non-GUI version.

However, the clipboard isn't shared between the devices.

Attaching the server logfiles _clipcascade-server-clipcascade-1_logs.txt

Happy to share more logs if required!

Sathvik-Rao commented 1 month ago

Hi @davebooi,

The Step 3: Install Gtk 3.0 for Clipboard Sharing has not been done properly because you are using a virtual environment (venv).

To install GTK and GDK libraries, please use the following command:

sudo pacman -S gtk3 gdk-pixbuf2

Edit: If the issue still exist I will try on Arch Linux

davebooi commented 1 month ago

Thanks again for your help on this, appreciated.

All the necessary packages are installed. In Arch I need to create a virtual environment to install the pip requirements, hence the use of venv.

Sathvik-Rao commented 1 month ago

Hi @davebooi

Please remove the existing ClipCascade code from your machine and reinstall the ClipCascade_Linux_Terminal.zip file. Then, follow these instructions (there's no need to create a virtual environment)

sudo pacman -Syu --noconfirm python python-pip python-gobject xclip
sudo pacman -S --noconfirm python-xxhash python-pyperclip python-requests python-websocket-client python-pycryptodome python-pyfiglet
sudo pacman -S --noconfirm python-gobject gtk3
sudo python3 main.py
davebooi commented 1 month ago

I followed the description step by step, uninstalled previous versions and am using it without a virtual environment at the moment. The error message is still present upon start:

image

Sathvik-Rao commented 1 month ago

I tested it on Arch, and it worked fine for me.

In your case, it seems GTK couldn't access the clipboard for the current display, likely because no valid display was detected. Is the program running in a headless environment or a virtual machine?

can you share the output for echo $DISPLAY

davebooi commented 1 month ago

strange indeed, I'm using Hyprland as a Window Manager.

The output of echo $DISPLAY is :0

image

Sathvik-Rao commented 1 month ago

Hi @davebooi

I’ll reinstall it once I have some free time and will keep you updated.

Sathvik-Rao commented 6 days ago

Hi @davebooi,

I apologize for the delay. The new terminal app has been released, and it now works on all Linux distros.

Thank you!

davebooi commented 6 days ago

I can indeed confirm that the latest version is working as intended! Clipboard sync works on mobile & laptop with

arch Hyprland 0.4.5 ClipCascade version 1.1.0

Appreciate the time you took to fix this - thanks!