Closed jackroi closed 2 months ago
Solution 2
Change
isNothing
withisJust
I'd imagine the code is just an unfortunate typo, making this the safest option.
I find "delete empty workspaces upon switching off of them" to be quite surprising behaviour, though. Perhaps people who use the module find this convenient? Since the behaviour seems to have been broken for close to 10 years, maybe not so much :)
With any contrib that old, the real question is whether anyone has used it since it was added. 😁
Yes, solution 2 is the safest. However, I would prefer solution 1, since as you say it's a surprising behaviour, and I would prefer to delete a project when I consider it ended, and not when it happens to have no windows. And after all, I don't expect no one to rely on this behaviour since it is an old bug and it's not documented.
With any contrib that old, the real question is whether anyone has used it since it was added. 😁
I switched to XMonad recently, and I was really happy when I discovered this module, since it does exactly what I need.
Yes, solution 2 is the safest. However, I would prefer solution 1, since as you say it's a surprising behaviour, and I would prefer to delete a project when I consider it ended, and not when it happens to have no windows. And after all, I don't expect no one to rely on this behaviour since it is an old bug and it's not documented.
That's fine with me; do you want to prepare a PR?
Yes, I will try later today.
Problem Description
When switching to a project (from XMonad.Actions.DynamicProjects) from a static workspace (ie. defined in
xmonad.hs
) that contains no windows, the initial workspace gets removed.Example:
switchProject tempProject
while focus is on workspace 1. Workspaces: before -> after Actual:[*1,2,3] -> [2,3,*TMP]
Expected:[*1,2,3] -> [1,2,3,*TMP]
switchProject
semanticThe function
switchProject :: Project -> X ()
is supposed to create and focus a dynamic workspace, and run the associated start-up hook. By inspecting the source code, I found the following:https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L265-L266
that clearly indicates the will of the author to delete the focused project when it is empty (however this is neither documented nor working). Then in another part of the code:
https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L218-L220
suggesting that he didn't want that functionality.
Moreover there are 2 related commits: The first (Dec, 2015) is exactly about this problem, and the commit message says:
The [second]() (Nov 2016) mentions in the changelog:
The bug
The incriminated code is this: https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L256-L271
Given the previous context, this part of the function: https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L267-L269 is either not wanted at all (don't really want to remove a project when switching away from it, even if it is empty), or if the project deletion is wanted, it is bugged, in fact a "user created project" (will come back to this later) has always the field
projectStartHook = Just
, due todynamicProjectsStartupHook
function: https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L205-L224 where in the last lines, if a project hasprojectStartHook = Nothing
it is forced toprojectStartHook = Just (return ())
.Line 260 of
switchProject
uses the functioncurrentProject
to obtain current project: https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L232-L238 https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L357-L359 This function always return a Project, even for standard workspaces, with the difference thatprojectStartHook = Nothing
(this is a sort of fake project that can never be created by a user). Sooldp
will contain either:Just (return ())
), when the current workspace is a project;So the check
isNothing ...
https://github.com/xmonad/xmonad-contrib/blob/b3c249434d7482eb9dee236b150f7a8fba0380ce/XMonad/Actions/DynamicProjects.hs#L267 will always return true for non projects, and never return true for project, that is the opposite of what we want.Possible solutions
Solution 1
Solution 2
Change
isNothing
withisJust
Solution 3
projectStartHook
with a dummyJust (return ())
indynamicProjectsStartupHook
currentProject
return a Maybe, instead of building a fake Project.isNothing (projectStartHook oldp)
withisJust oldP
This is however a breaking change since
currentProject :: X Project
is exported. In any case, I think it should be documented that it returns a project withprojectStartHook = Nothing
.Deleting projects
Finally, provide a way to delete projects manually. After all, deleting projects only when switching to other projects is not a sufficient way to close all the projects.
Steps to Reproduce
switchProject
orswitchProjectPrompt
.Configuration File
Checklist
[x] I've read CONTRIBUTING.md
I tested my configuration
xmonad
version 0.18.0-14xmonad-contrib
version 0.18.0-14