Skip to content

Conversation

minad
Copy link
Member

@minad minad commented Dec 23, 2024

exwm-enable: Set environment variables and x-no-window-manager

* exwm.el (exwm-enable): Set environment variables XDG_CURRENT_DESKTOP and
XDG_SESSION_DESKTOP such that EXWM can be detected inside nested Emacs sessions.
Furthermore set `x-no-window-manager' which tells Emacs to not wait for the
window manager, which with EXWM, is itself.

@minad minad requested a review from Stebalien December 23, 2024 18:52
@minad
Copy link
Member Author

minad commented Dec 23, 2024

@Stebalien Which approach do you use to handle Emacs nesting? This is not my common setup, but nevertheless I sometimes like to start a nested Emacs instance and then I need to detect the outer EXWM. This also applies to scripts which want to detect the window manager. Maybe we can use a (quasi-)standardized variable for the active window manager, e.g., set XDG_CURRENT_DESKTOP and XDG_SESSION_DESKTOP (DESKTOP, SESSION, DESKTOP_SESSION, ...) to exwm?

@minad minad changed the title exwm-enable: Set env INSIDE_EXWM and x-no-window-manager exwm-enable: Set environment variables and x-no-window-manager Dec 23, 2024
@Stebalien
Copy link
Member

I don't use a nested setup but I do set an EXWM=1 environment variable (which is a bit of a hack, I admit). IMO, setting the XDG variables is likely better, but we should expect a bit of breakage from Gnome packages (IIRC).

I set x-no-window-manager as well.

@minad minad self-assigned this Dec 23, 2024
@minad
Copy link
Member Author

minad commented Dec 23, 2024

IMO, setting the XDG variables is likely better, but we should expect a bit of breakage from Gnome packages (IIRC).

Which breakage do you expect? Do you have some references?

@minad
Copy link
Member Author

minad commented Dec 23, 2024

Hmm, I looked a bit around and found some discussions:

So it seems that most window managers don't set this and leave the responsibility to the login or session script. Unfortunately this won't work for the purpose of detecting EXWM and determining if EXWM should be started or not, since for this to work the variable must be set inside Emacs itself. I think this leaves us no other choice than going with a custom variable, even if a little bit hackish?

@Stebalien
Copy link
Member

Which breakage do you expect? Do you have some references?

At this point, all I remember is a vague "it caused some problems". But that was a while ago and I didn't put any effort into resolving those issues (and I might just be misremembering the entire thing). So I'd just go for it.

@Stebalien
Copy link
Member

So it seems that most window managers don't set this and leave the responsibility to the login or session script. Unfortunately this won't work for the purpose of detecting EXWM and determining if EXWM should be started or not, since then the variable must be set by EXWM itself. I think this leaves us no other choice than going with a custom variable, even if a little bit hackish?

Technically it should be set by the login manager, but, IMO, setting it if it's not already set is also reasonable.

@minad
Copy link
Member Author

minad commented Dec 23, 2024

Technically it should be set by the login manager, but, IMO, setting it if it's not already set is also reasonable.

Agree. However it won't work for the nested Emacs purpose then if it could also have been set already from outside.

@Stebalien
Copy link
Member

Agree. However it won't work for the nested Emacs purpose then if it could also have been set already from outside.

How so? If we change it from within Emacs, all Emacs sub-processes will inherit the new value.

@minad
Copy link
Member Author

minad commented Dec 23, 2024

How so? If we change it from within Emacs, all Emacs sub-processes will inherit the new value.

It is a hypothetical case, since the login manager doesn't set the variable yet to EXWM. But assume it would set XDG_CURRENT_DESKTOP=EXWM, then the following check wouldn't work in the init.el:

(unless (equal "XDG_CURRENT_DESKTOP" "EXWM")
   (exwm-enable))

The check is needed for the aformentioned nesting of Emacs instances.

(I've added a commit to the master branch for now which only sets the x-no-window-manager variable.)

@Stebalien
Copy link
Member

Oh, I see. Yeah, that wouldn't work. Honestly, for that I'd just check the INSIDE_EMACS variable.

@Stebalien
Copy link
Member

Ah... and that's set regardless, I thought that was only set in sub-shells.

@minad
Copy link
Member Author

minad commented Dec 23, 2024

Ah... and that's set regardless, I thought that was only set in sub-shells.

(getenv "INSIDE_EMACS") evaluates to nil. Nevertheless I originally had planned to set the INSIDE_EXWM environment variable in exwm-enable which mirrors INSIDE_EMACS.

@Stebalien
Copy link
Member

(getenv "INSIDE_EMACS") evaluates to nil. Nevertheless I originally had planned to set the INSIDE_EXWM environment variable which mirrors INSIDE_EMACS.

It evaluates to 31.0.50,emacs on my system but... that may be just my config.

But INSIDE_EXWM sounds reasonable.

@minad
Copy link
Member Author

minad commented Dec 23, 2024

It evaluates to 31.0.50,emacs on my system but... that may be just my config.

I am still on 30, but there INSIDE_EMACS is only non-nil inside Eshell. In the scratch buffer it evaluates to nil. But anyway, I think this is not reliable enough. So let's just go with INSIDE_EXWM.

* exwm.el (exwm-enable): Set environment variable INSIDE_EXWM such that EXWM can
be detected inside nested Emacs sessions.
@minad minad merged commit ac80bf1 into master Dec 23, 2024
@minad minad deleted the minad/set-vars branch December 23, 2024 21:20
@Stebalien
Copy link
Member

I am still on 30, but there INSIDE_EMACS is only non-nil inside Eshell. In the scratch buffer it evaluates to nil. But anyway, I think this is not reliable enough. So let's just go with INSIDE_EXWM.

Oh, lol. That's my fault. I got annoyed at it only showing up in shells so I set it globally so I can detect emacs from all sub-processes. (my config is way too big at this point)

@minad
Copy link
Member Author

minad commented Dec 23, 2024

Oh, lol. That's my fault. I got annoyed at it only showing up in shells so I set it globally so I can detect emacs from all sub-processes. (my config is way too big at this point)

Okay, I see. I still think INSIDE_EXWM is a good variable to have :)

@QiangF
Copy link

QiangF commented Dec 25, 2024

I use lxqt-session to start the window manager, and XDG_SESSION_DESKTOP is lxqt.
What is better if I have two window managers (exwm and herbstluftwm) for two people?
Should I set XDG_CURRENT_DESKTOP in the session manager and check both (XDG_CURRENT_DESKTOP=exwm and INSIDE_EXWM=false) to load the exwm specific configs?
@minad Can you share your configuration?
Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants