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

Support assigning programs to workspaces #31

Open
infokiller opened this issue Apr 6, 2020 · 10 comments
Open

Support assigning programs to workspaces #31

infokiller opened this issue Apr 6, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@infokiller
Copy link
Owner

From #30

i3 supports this, but it won't work correctly with workspace groups because the workspace names are changed for ordering the groups.

@infokiller infokiller added the bug Something isn't working label Apr 6, 2020
@Syphdias
Copy link

Syphdias commented Aug 19, 2020

I was looking for that feature as well and was wondering why the naming scheme is what it is.

I haven't looked at the code; maybe it is obvious. Just from observing the it looks like every group has a big number 100100, 100200, etc. and the current selected one is 100000. So I assume the ids are build like this:
100000 (?) + group_id*100 + ws_id
I'm not quite sure what the offset 1000 is for. What would happen if you dropped the 100000 and made the selected_group_id=0 (which it already as as far as I can tell). I think in an older version of i3 this might have been necessary because it would sort the characters instead of ids (eg. 10, 1, 2, ...) – not sure though.

So if you drop 100000 lots of native commands would work again for the current workspace (this wouldn't close this issue if you want to support assigning to specific workspaces but it might open other possibilities) Workspaces would be named like this:

  • 1:dogs:First WS In Selected Group dogs:1
  • 5:dogs:Fifth WS In Selected Group dogs:5
  • 101:First WS In Default WS:1
  • 102:Second WS In Default WS:2
  • 203:cats:Third WS In CATS:3
  • 204:cats:Fourth WS In CATS:4

PS: Would probably also make it possible to up the group and workspace limits if i3 ids were the limitation here – not that one would use all of them 😂

@infokiller
Copy link
Owner Author

The 100000 is coming from the monitor index. Are you using multiple monitors?
If so, the first of them shouldn't have an extra 100000. Example workspaces:

Monitor 1:

1:dogs:bulldogs:1
2:dogs:dalmatian:2
101:cats:siamese:1

Monitor 2:

100001:rabbits:rex:1

@Syphdias
Copy link

🤦 Apparently I only tested on my second monitor, sorry. It's even in the REAME...
Also explains some unexpected behavior 😅

@Syphdias
Copy link

Do you open the media/games once in their dedicated workspace and then just leave them there and forget about them?

One workaround for having a program assigned to a specific workspace is to first open that workspace (for example, by switching to the Games group and then optionally rename it and change its number), and only then open the program. I would think this workaround is reasonably if you don't open these programs frequently, but it's annoying if you do. Am I right?

So I have three special workspaces:

  • Games: The purpose is to separate games from all other containers. I assign them to this because I launching can take a few seconds and I don't want to stay on that workspace (might want to switch to some music or video to play on the other monitor). So no, frequency is not an issue in this case but delay (If the Game requires a launcher you have this delay twice). Also what I described in multiple monitors group switching #29 (comment): You really want to have the fully screen games away from tiling windows. They don't place nicely.
  • Audio: The workspace I dedicate for opening music players like spotify or YouTube with music. In this case the workaround would work; I open those things once and only switch occasionally to get something new.
  • Communication: For Messengers and other communications, out of the way but easy to access if I need to always at the same place

Stupid question: I mentioned that just naming a workspace a certain way will not make it work with i3-workspace-groups. Why is that the case? I would have expected parsing like this:

ws_array = workspace_name.split(":")
global_id = ws_array[0]
local_id = ws_array[-1]
if len(ws_array) > 2:
    name = ws_array[-2]
if len(ws_array) == 4:
    group_name = ws_array[1]

I suspect something more complicated at play. Characters I don't see or maybe the groups colon in not the same colon or something...

@infokiller
Copy link
Owner Author

Thanks for the explanation!

Re the workspace name parsing, it's very similar to what you described, but the splitting is actually done by a Unicode Zero Width Space. This way, parsing is slightly easier because you always expect to have 5 sections/fields, and you can also have colons if the sections (group, workspace name) if you want. For more details see the comment at the top of https://github.com/infokiller/i3-workspace-groups/blob/master/i3wsgroups/workspace_names.py.

The problem with assigning programs to workspaces is that the workspace names in i3-workspace-groups are dynamic. They can change because the global number (what you called global_id in the code above) changes based on the group order, and they can also change if you use i3-autoname-workspaces to get icon names.

To solve this, I will need to add another daemon like i3-autoname-workspaces that does the assignments based on the static fields (group name, local name, and local number).

@Syphdias
Copy link

Just some notes which might be relevant for this issue.

Usual way how to assign:

assign [class="vlc"] $ws0

But since some programs, like Spotify, have a buggy X11 implementation(?) it needs to be done like this:

for_window [class="Spotify"] move to --no-auto-back-and-forth workspace $ws0

Something similar can be achieved with i3-workspace-groups (right now):

for_window [class="Spotify"] exec --no-startup-id ~/.local/bin/i3-workspace-groups move-to-number --group-name "" 10

But:

  • There is no no-back-and-forth option which will lead to wrong behavior if you are already on workspace 10
  • The first two also set the workspace's group name, e.g. 10:Media. There is i3-workspace-groups rename-workspace --name $name but this only lets you set the name of the current workspace

infokiller added a commit that referenced this issue Sep 24, 2020
@infokiller
Copy link
Owner Author

@Syphdias I added support for the --no-auto-back-and-forth flag in the latest pre-release version. Install it using python3 -m pip install --pre --force-reinstall i3-workspace-groups.

@jcelerier
Copy link

@Syphdias I tried your solution but with many workspaces the behaviour is completely random...

for_window [title="HDSPMixer"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [class="FLTK"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [class="qjackctl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [title="qjackctl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [instance="qjackctl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [class="QjackCtl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [title="QjackCtl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [instance="QjackCtl"] $exec_i3_groups move-to-number --group-name "audio" 1
for_window [class="strawberry"] $exec_i3_groups move-to-number --group-name "audio" 1

for_window [class="qtcreator"] $exec_i3_groups move-to-number --group-name "dev" 1
for_window [class="QtCreator"] $exec_i3_groups move-to-number --group-name "dev" 1

for_window [class="firefox"] $exec_i3_groups move-to-number --group-name "web" 1
for_window [title="firefox"] $exec_i3_groups move-to-number --group-name "web" 1
for_window [instance="firefox"] $exec_i3_groups move-to-number --group-name "web" 1

for_window [class="Mail"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [title="Mail"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [instance="Mail"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [class="Thunderbird"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [title="Thunderbird"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [instance="Thunderbird"] $exec_i3_groups move-to-number --group-name "social" 1
for_window [class="telegram-desktop"] $exec_i3_groups move-to-number --group-name "social" 2
for_window [class="ripcord"] $exec_i3_groups move-to-number --group-name "social" 2
for_window [class="Ripcord"] $exec_i3_groups move-to-number --group-name "social" 2

exec --no-startup-id i3-workspace-groups switch-active-group audio
exec hdspmixer 
exec qjackctl 
exec strawberry 

exec telegram-desktop
exec ripcord
exec thunderbird

exec qtcreator -noload ClangFormat score

exec firefox https://gmail.com

gives me everything moving to random workspaces whenever a new app pops up

@Syphdias
Copy link

Syphdias commented Oct 3, 2020

What I did not think about when suggesting the solution was that for_window does not provide context but only the trigger. Thus it will move the current focused window I fear.

@jcelerier
Copy link

yep, there really doesn't seem a way to do that actually statelessly..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants