Skip to content
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

Create exwm-minor-mode #868

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Create exwm-minor-mode #868

wants to merge 1 commit into from

Conversation

medranocalvo
Copy link
Collaborator

With this change I intend to convert EXWM into a global minor mode.

Please check out and test.

Next steps would be e.g. creating a menu for the minor mode where workspaces can be managed (at the moment the menu is only available when an EXWM-mode buffer is current). Please discuss further ideas.

@jsilve24
Copy link

Interesting. What is the rationalle behind this change?

* exwm.el (exwm-minor-mode): New function.
(exwm-enable, exwm-disable, exwm-init, exwm-exit): Deprecate in
favor of `exwm-minor-mode'.
(exwm--init): Rework to signal errors and cleanup in case of
errors.
(exwm--exit): More thorough cleanup.
(exwm--cleanup): New function.
(exwm--on-SelectionClear, exwm--confirm-kill-emacs): : Use
`exwm--exit'.
(exwm--terminal-x-p, exwm--find-any-x-frame)
(exwm--init-on-window-setup-hook)
(exwm--init-on-after-make-frame, exwm--cleanup): New functions.
(exwm--wmsn-acquire): Signal error instead of using `user-error'.
@medranocalvo
Copy link
Collaborator Author

A minor mode is some feature that can be enabled and disabled. When enabled, it adds to or alters Emacs' capabilities, binds commands to some keys, shows some menus, etc. This fits EXWM functionality. Indeed, EXWM does all of this already, some of it in some peculiar ways. I'd like to make EXWM less peculiar (where possible), and this is a small step in that direction.

There are no functionality changes, though some of the entrypoints (e.g. exwm-enable) become obsolete.

@ArneBab
Copy link

ArneBab commented Aug 28, 2023

Can exwm as minor mode restore the previous window manager (if there was one)?

@Stebalien
Copy link
Contributor

Can exwm as minor mode restore the previous window manager (if there was one)?

That's generally not possible to do reliably. Many window managers are components of larger systems.

@ArneBab
Copy link

ArneBab commented Sep 4, 2023

It seems to be possible with xprop: https://askubuntu.com/a/1153698/329876

id=$(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}'); xprop -id "${id}" -notype -f _NET_WM_NAME 8t | grep "_NET_WM_NAME = " | cut --delimiter=' ' --fields=3 | cut --delimiter='"' --fields=2

I’m asking because if I were to disable the minor-mode, I would not have a wm and that could cause Emacs to lose keyboard focus, leaving me without an ability to start another wm.

Would it maybe be possible to do this with a fallback? If there was a wm before (exwm already detects that) then use the detected wm and if that fails (or the previous one cannot be detected) use a fallback wm?

@Stebalien
Copy link
Contributor

That returns the window manager's name but that's not enough to restore it. EXWM would need to know how to start the window manager and most window managers expect to run within a specific environment (e.g., managed by a session manager).

@ArneBab
Copy link

ArneBab commented Sep 5, 2023

Aren’t you usually already in that environment if exwm replaced the window manager? (just starting the window manager by hand usually worked for me, if I could find out which one was used by the session manager)

@Stebalien
Copy link
Contributor

Stebalien commented Sep 5, 2023 via email

@medranocalvo
Copy link
Collaborator Author

Indeed, we could read the previous WM name before replacing it. I see the following challenges:

  1. Finding out the command needed to start the previous WM again. We'd need to compile a dictionary matching the WM name to the command needed for launching it. This research seems laborious to me, but I think it would be worthwhile if we succeed in restarting some frequently used WMs. I implemented the replace functionality to ease trying out EXWM without the need to modify .xinitrc files; being able to restore the environment after trying would be a step further in that direction. As @Stebalien points out, this might be impracticable.
  2. Invoking that command in such a way that it's not killed when exiting Emacs.
  3. ???

@ArneBab, would you be willing to work on this? I have very limited time, but would try to support you as possible. Please note that EXWM is part of GNU Emacs, so copyright assignment to the FSF would be needed.

At last, I'd like to point out that restarting the previous WM is orthogonal to this particular change: although a minor mode leads itself to being activated and deactivated, exwm-exit existed previously.

Thank you.

@ArneBab
Copy link

ArneBab commented Sep 5, 2023

@medranocalvo I have no problem with copyright assignment to GNU — can you send me the papers? (do you have my email address?)

This would make temporary exwm sessions more practical for me, so I would try to work on this (I likely won’t be fast, though, already too many projects on my plate).

My experience is that just starting another wm worked well enough for me. The hardest challenge was to remember or find the name of the window manager (or just start another one, they may not be fully interchangeable, but just having any window manager already makes most desktop environments work again).

@medranocalvo
Copy link
Collaborator Author

@medranocalvo I have no problem with copyright assignment to GNU — can you send me the papers? (do you have my email address?)

Please, have a look at https://www.gnu.org/software/emacs/manual/html_node/emacs/Copyright-Assignment.html.

This would make temporary exwm sessions more practical for me, so I would try to work on this (I likely won’t be fast, though, already too many projects on my plate).

Tell me about time! I suggest you to open a PR with whatever first questions you might have. Have a look at exwm--wmsn-acquire; perhaps a new option restore to exwm-replace...

My experience is that just starting another wm worked well enough for me. The hardest challenge was to remember or find the name of the window manager (or just start another one, they may not be fully interchangeable, but just having any window manager already makes most desktop environments work again).

I tested various WMs while developing replace support (#380). For me their --replace functionality (which not all of them support) was important, but it's not needed for our purposes: we can shut down EXWM before restarting the old WM.

@medranocalvo
Copy link
Collaborator Author

I just remembered that I had issues using EXWM replace functionality under GNOME last time I tried. When replacing the WM, I got a gigantic dialog whose only button would kill the session. What I remember from my (non) understanding at the time is that unless the WM registers with the login manager (?) it will consider the session idle (?) and terminate it. @Stebalien, is something like that what you had in mind?

See https://man.archlinux.org/man/systemd-logind.service.8.en.

@Stebalien
Copy link
Contributor

Stebalien commented Sep 7, 2023 via email

@medranocalvo
Copy link
Collaborator Author

@Stebalien: thank you for your explanation. You are right: we won't be able to recover to custom setups. I'm also not sure whether we will be able to recover to complex standard setups, say GNOME4 with the login manager. The objective is, as far as I'm concerned, making it seamless to try out EXWM (@ArneBab has a different but compatible objective, if I understood correctly).

@ArneBab: the following let's us recover XFCE4 after replacing it with EXWM.

(call-process "xfwm4" nil 0 nil "--replace")

Seems to continue working after killing Emacs after replacing EXWM with XFWM4.

@ArneBab
Copy link

ArneBab commented Sep 13, 2023

@medranocalvo This would already make it much more painless to try exwm. Currently when I quit Emacs, I have to somehow start another window manager, which often means closing window after window until I finally get keyboard focus on a shell. Getting rid of that would go a long way to make a quick test more enjoyable.

@Stebalien Stebalien mentioned this pull request Dec 31, 2023
6 tasks
@medranocalvo
Copy link
Collaborator Author

I want to note that exwm-mode is ready, as far as I remember. I'll rebase and post a new PR in @emacs-exwm.

I find the restarting the replaced WM is important feature for trying out EXWM. I'll open a ticket on @emacs-exwm and will try to work on it (no promises).

@minad
Copy link
Contributor

minad commented Jan 16, 2024

Thanks, I like this change. I wonder if we should also change the scheme for the extensions, introducing exwm-xsettings-mode instead of exwm-xsettings-enable etc. What do you think?

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.

5 participants