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

Question: i3 with xmonad multiscreen behaviour #1

Open
caillou opened this issue May 5, 2018 · 1 comment
Open

Question: i3 with xmonad multiscreen behaviour #1

caillou opened this issue May 5, 2018 · 1 comment

Comments

@caillou
Copy link

caillou commented May 5, 2018

I just finished watching your video on tiling window managers. I have to say, this is one of the best presentations I have seen in a long time.

Now, in your talk you mentioned that you managed to have swapping workspaces in i3 in the same way xmonad does it.

Could you give me a hint at to how you achieved this? This would be the icing on the cake…

@HappyTetrahedron
Copy link
Owner

Hi! It's been a while, but I apparently accidentally disabled notifications for this repository.

This is the script I still use today (requires jshon to be installed):

#!/bin/bash

# get relevant info from i3-msg
WORKSPACEJSON="$(i3-msg -t get_workspaces)"

WORKSPACES="$(echo "$WORKSPACEJSON" | jshon -a -e name -u)"
MONITORS="$(echo "$WORKSPACEJSON" | jshon -a -e output -u)"
FOCUSED="$(echo "$WORKSPACEJSON" | jshon -a -e focused)"
VISIBLE="$(echo "$WORKSPACEJSON" | jshon -a -e visible)"

# FROMNR is the number of the currently focused workspace. TONR is the number of the workspace I want to switch to.
FROMNR="$(echo "$FOCUSED" | nl | grep true | awk '{print $1}')"
TONR="$(echo "$WORKSPACES" | awk '{print "__"$1}' | nl | grep "__$1" | awk '{print $1}')" # Since workspace names can be numbers, grep could accidentally find a line number, so workspace names are prefixed with __ to avoid that

# i3 names of the workspaces to switch. 
FROMNAME="$(echo "$WORKSPACES" | sed "$(echo $FROMNR)q;d")"
TONAME="$1"

# Monitors on which both workspaces reside
FROMMONI=$(echo "$MONITORS" | sed "$(echo $FROMNR)q;d")
TOMONI=$(echo "$MONITORS" | sed "$(echo $TONR)q;d")

# "true" if target workspace is currently visible, "false" otherwise
TOVISI=$(echo "$VISIBLE" | sed "$(echo $TONR)q;d")

# Target workspace doesn't exist yet, or is on same monitor as current
if [[ "$TONR" = "" ]] || [[ "$FROMMONI" = "$TOMONI" ]]
then
    i3-msg "workspace $TONAME" # simple WS switch as with default i3
else
    if [[ "$TOVISI" = "true" ]] # If target workspace is visible
    then
        i3-msg "move workspace to output $TOMONI" # the current WS is moved to replace it
    fi

    # Target workspace is first selected and then moved to current monitor.
    i3-msg "workspace $TONAME" 
    i3-msg "move workspace to output $FROMMONI"
    i3-msg "focus output $FROMMONI" 
fi

In my i3 config, I simply invoke this script using exec instead of doing the regular workspace switch (my script is called switchworkspace and added to the path):

# switch to workspace
bindsym $mod+1 exec switchworkspace 1
bindsym $mod+2 exec switchworkspace 2
bindsym $mod+3 exec switchworkspace 3
bindsym $mod+4 exec switchworkspace 4
bindsym $mod+5 exec switchworkspace 5
bindsym $mod+6 exec switchworkspace 6
bindsym $mod+7 exec switchworkspace 7
bindsym $mod+8 exec switchworkspace 8
bindsym $mod+9 exec switchworkspace 9
bindsym $mod+0 exec switchworkspace 10

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

No branches or pull requests

2 participants