lanoxx / tilda

A Gtk based drop down terminal for Linux and Unix
GNU General Public License v2.0
1.28k stars 161 forks source link

"cannot open display" - Tilda fails to start with systemd #410

Open amo13 opened 4 years ago

amo13 commented 4 years ago

I want to make tilda start automatically when I login and made this little systemd unit for that purpose:

.config/systemd/user/tilda.service

[Unit]
Description=Tilda drop-down terminal

[Service]
ExecStart=tilda --dbus

[Install]
WantedBy=default.target

unfortunately, after login, the journal shows this:

Apr 10 09:59:34 bodet-pc systemd[1541]: Started Tilda drop-down terminal.
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: main: Using libvte version: 0.60.1
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: remove_stale_lock_files
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: islockfile
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: create_lock_file
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: get_instance_number
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: islockfile
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: create_lock_file
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda-cli-options.c: FUNCTION ENTERED: parse_cli
Apr 10 09:59:34 bodet-pc tilda[1550]: tilda.c: FUNCTION ENTERED: get_config_file_name
Apr 10 09:59:34 bodet-pc tilda[1550]: cannot open display: 
Apr 10 09:59:34 bodet-pc systemd[1541]: tilda.service: Main process exited, code=exited, status=1/FAILURE
Apr 10 09:59:34 bodet-pc systemd[1541]: tilda.service: Failed with result 'exit-code'.

The error is the same on X and on wayland.

amo13 commented 4 years ago

Interestingly, if after login I launch a terminal and do systemctl --user start tilda, it successfully starts:

Apr 10 10:17:08 bodet-pc systemd[5077]: Started Tilda drop-down terminal.
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: main: Using libvte version: 0.60.1
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: remove_stale_lock_files
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: islockfile
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: create_lock_file
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: get_instance_number
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: islockfile
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: create_lock_file
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda-cli-options.c: FUNCTION ENTERED: parse_cli
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda.c: FUNCTION ENTERED: get_config_file_name
Apr 10 10:17:08 bodet-pc tilda[6287]: configsys.c: FUNCTION ENTERED: config_init
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_window.c: FUNCTION ENTERED: tilda_window_init
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_window.c: FUNCTION ENTERED: tilda_window_set_fullscreen
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_window.c: FUNCTION ENTERED: tilda_window_add_tab
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_term_init
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_term_config_defaults
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_term_adjust_font_scale
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_term_set_scrollbar_position
Apr 10 10:17:08 bodet-pc tilda[6287]: void vte_terminal_match_set_cursor_type(VteTerminal*, int, GdkCursorType): assertion 'tag >= 0' failed
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: start_shell
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_switch_page_cb
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_get_title
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_get_title
Apr 10 10:17:08 bodet-pc tilda[6287]: key_grabber.c: FUNCTION ENTERED: generate_animation_positions
Apr 10 10:17:08 bodet-pc tilda[6287]: Virtual modifier for 'caps_lock_mask' set to: GDK_LOCK_MASK
Apr 10 10:17:08 bodet-pc tilda[6287]: Virtual modifier for 'num_lock_mask' set to: GDK_MOD2_MASK
Apr 10 10:17:08 bodet-pc tilda[6287]: Virtual modifier for 'scroll_lock_mask' set to: 
Apr 10 10:17:08 bodet-pc tilda[6287]: Activating D-Bus interface on bus name: com.github.lanoxx.tilda.Actions0
Apr 10 10:17:08 bodet-pc tilda[6287]: Tilda has started. Press <Shift><Alt>t to pull down the window.
Apr 10 10:17:08 bodet-pc tilda[6287]: Resolved accelerator: <Shift><Alt>t. KeySymbol: 116, Virtual Modifiers: GDK_SHIFT_MASK | GDK_MOD1_MASK
Apr 10 10:17:08 bodet-pc tilda[6287]: Binding to keycode 28
Apr 10 10:17:08 bodet-pc tilda[6287]: Binding to real modifier mask 9 (GDK_SHIFT_MASK | GDK_MOD1_MASK)
Apr 10 10:17:08 bodet-pc tilda[6287]: Added binding. Keystring: <Shift><Alt>t
Apr 10 10:17:08 bodet-pc tilda[6287]: key_grabber.c: FUNCTION ENTERED: pull
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: shell_spawned_cb
Apr 10 10:17:08 bodet-pc tilda[6287]: TildaDbusActions: Name acquired: com.github.lanoxx.tilda.Actions0
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: window_title_changed_cb
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_get_title
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_get_title
Apr 10 10:17:08 bodet-pc tilda[6287]: tilda_terminal.c: FUNCTION ENTERED: tilda_terminal_get_title
lanoxx commented 4 years ago

When you start tilda via the gnome-session, then the DISPLAY environment variable is set by gnome-session-binary (see man gnome-session) after your session has been initialized. According to https://wiki.archlinux.org/index.php/Systemd/User there should be a script for systemd that does the same. If tilda is not seeing that variable it could be that the systemd user slice is starting the tilda service too early in the process, when the display does not exist yet. Try to find another target to bind the tilda service to that comes later in the session initalization phase when the X releated parts of the session have already been correctly setup. I think if tilda is started too early that can also break the transparency feature, because tilda will be able not detect that transparency is available.

lanoxx commented 4 years ago

If you are on a GNOME desktop, then this might help: https://gitlab.gnome.org/GNOME/gnome-session/-/merge_requests/13/diffs#diff-content-43cf1a54a4dcd028e0763ae326787bcab2ac4b4a

Requisite=gnome-session-initialized.target
BindsTo=gnome-session-initialized.target
After=gnome-session-initialized.target
amo13 commented 4 years ago

You are awesome for looking further into this and helping out with systemd initialization! I was looking for the exact same .target to put into the unit file. Unfortunately, it does not seem to work just yet..., still getting

● tilda.service - Tilda drop-down terminal
     Loaded: loaded (/home/amo/.config/systemd/user/tilda.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-05-03 13:27:08 CEST; 24s ago
    Process: 2591 ExecStart=/usr/bin/tilda --dbus (code=exited, status=1/FAILURE)
   Main PID: 2591 (code=exited, status=1/FAILURE)

Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: islockfile
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: create_lock_file
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: get_instance_number
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: islockfile
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: create_lock_file
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda-cli-options.c: FUNCTION ENTERED: parse_cli
Mai 03 13:27:08 bodet-pc tilda[2591]: tilda.c: FUNCTION ENTERED: get_config_file_name
Mai 03 13:27:08 bodet-pc tilda[2591]: cannot open display: 
Mai 03 13:27:08 bodet-pc systemd[2547]: tilda.service: Main process exited, code=exited, status=1/FAILURE
Mai 03 13:27:08 bodet-pc systemd[2547]: tilda.service: Failed with result 'exit-code'.

I'll try with a wayland session (this was X)

amo13 commented 4 years ago
Requisite=gnome-session-initialized.target
BindsTo=gnome-session-initialized.target
After=gnome-session-initialized.target

Oh wow, this actually breaks login to wayland session completely... When trying to login, it just brings me back to the greeter with the login prompt. On X it also breaks a few things: On first login I just got a message telling me that something was wrong and that the session could not be started. The second login attempt did work, but the shutdown menu for example stopped showing up when clicked from the status bar menu...

lanoxx commented 2 years ago

I also did not have much success with the gnome-session-initialized.target. In journalctl --user -b I can see that gnome-session-initialized.target seems to run before gnome-session-x11.target, so that might be too early in the start up sequence.

May 08 21:28:10 earth systemd[2481]: Reached target GNOME Session is initialized. May 08 21:28:10 earth systemd[2481]: Reached target GNOME session X11 services.

After some more research I finally learned that systemd has a graphical-session.target on which a session unit can depend on:

[Unit]
...
PartOf=graphical-session.target

[Service]
...

[Install]
WantedBy=graphical-session.target

Using that I was able to write a user service that runs an X11 program which has access to the DISPLAY and XAUTHORITY variables and that allowed me to run an X11 program in the session.

See also: https://superuser.com/a/1720018/194998