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

Can not detect correct focused workspace without using i3 specific command. #2921

Closed
snippins opened this Issue Sep 10, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@snippins

snippins commented Sep 10, 2017

i3 version:

Binary i3 version: 4.14-3-g7251553
Also appear in current 4.14 stable version.
Did not tested with earlier versions of i3

What I did and saw:

+Dragging a window from workspace A to B on a multi-monitors setup.
+Open a terminal and use "wmctrl -d" to check the focused workspace. Get A as the focused workspace
+Open a terminal and use "i3-msg -t get_workspaces " to check the focused workspace. Get B as the focused workspace.

What I expected instead:

"wmctrl -d" correctly see B as the focused workspace.

Additional info

The tint2 panel also appear to incorrectly recognized the focused workspace, just like wmctrl. That is why I suspect it is i3 fault.

@i3bot

This comment has been minimized.

Show comment
Hide comment
@i3bot

i3bot Sep 10, 2017

I don’t see a link to logs.i3wm.org. Did you follow http://i3wm.org/docs/debugging.html? (In case you actually provided a link to a logfile, please ignore me.)

i3bot commented Sep 10, 2017

I don’t see a link to logs.i3wm.org. Did you follow http://i3wm.org/docs/debugging.html? (In case you actually provided a link to a logfile, please ignore me.)

@Airblader

This comment has been minimized.

Show comment
Hide comment
@Airblader

Airblader Sep 10, 2017

Member

I assume these tools read _NET_CURRENT_DESKTOP, so perhaps there's a path where we don't update this property correctly.

What happens if you switch focus once between the two workspaces (back and forth). Does wmctrl then display the correct workspace?

Member

Airblader commented Sep 10, 2017

I assume these tools read _NET_CURRENT_DESKTOP, so perhaps there's a path where we don't update this property correctly.

What happens if you switch focus once between the two workspaces (back and forth). Does wmctrl then display the correct workspace?

@snippins

This comment has been minimized.

Show comment
Hide comment
@snippins

snippins Sep 12, 2017

When using workspace back and forth feature nothing happen. I3 stuck to B and wmctrl stuck to A.

I have to switch to another workspace C, or focus the workspace B again (shortcut or i3-msg workspace B or wmctrl), then everything back to normal.

Base on the above behaviour, I use the following script to bypass this quirk for now, in case anyone need it

#!/usr/bin/env python3

import sys
import i3ipc
import Xlib
import Xlib.display
import setproctitle
import subprocess
from subprocess import call
from subprocess import Popen

setproctitle.setproctitle("i3_fix_workspace_focus")
screen = Xlib.display.Display().screen()
i3 = i3ipc.Connection()

def event_handler(i3, e):
    print("triggered")
    #focus previous workspace
    cmd_0 = "wmctrl -d | grep '*' | awk '{ print $1 }'"
    p1 = Popen(cmd_0, stdout=subprocess.PIPE, shell=True)
    out, err = p1.communicate()
    out = out.decode(sys.stdout.encoding).strip()
    print("out: ", str(out))
    

    focused = i3.get_tree().find_focused().workspace().name
    cmd =  "wmctrl -d | grep '" + "WA: N/A  " + str(focused) + "' | awk '{ print $1 }'"
    print(cmd)
    p2 = Popen(cmd, stdout=subprocess.PIPE, shell=True)
    out2, err2 = p2.communicate()
    out2 = out2.decode(sys.stdout.encoding).strip()
    print("out2: ", str(out2))

    call(["wmctrl", "-s", str(out)])
    call(["wmctrl", "-s", str(out2)])


i3.on('workspace::focus', event_handler)

# Start the main loop and wait for events to come in.
i3.main()

snippins commented Sep 12, 2017

When using workspace back and forth feature nothing happen. I3 stuck to B and wmctrl stuck to A.

I have to switch to another workspace C, or focus the workspace B again (shortcut or i3-msg workspace B or wmctrl), then everything back to normal.

Base on the above behaviour, I use the following script to bypass this quirk for now, in case anyone need it

#!/usr/bin/env python3

import sys
import i3ipc
import Xlib
import Xlib.display
import setproctitle
import subprocess
from subprocess import call
from subprocess import Popen

setproctitle.setproctitle("i3_fix_workspace_focus")
screen = Xlib.display.Display().screen()
i3 = i3ipc.Connection()

def event_handler(i3, e):
    print("triggered")
    #focus previous workspace
    cmd_0 = "wmctrl -d | grep '*' | awk '{ print $1 }'"
    p1 = Popen(cmd_0, stdout=subprocess.PIPE, shell=True)
    out, err = p1.communicate()
    out = out.decode(sys.stdout.encoding).strip()
    print("out: ", str(out))
    

    focused = i3.get_tree().find_focused().workspace().name
    cmd =  "wmctrl -d | grep '" + "WA: N/A  " + str(focused) + "' | awk '{ print $1 }'"
    print(cmd)
    p2 = Popen(cmd, stdout=subprocess.PIPE, shell=True)
    out2, err2 = p2.communicate()
    out2 = out2.decode(sys.stdout.encoding).strip()
    print("out2: ", str(out2))

    call(["wmctrl", "-s", str(out)])
    call(["wmctrl", "-s", str(out2)])


i3.on('workspace::focus', event_handler)

# Start the main loop and wait for events to come in.
i3.main()

orestisf1993 added a commit to orestisf1993/i3 that referenced this issue Dec 9, 2017

floating_maybe_reassign_ws: show workspace before focusing
With this change i3 will correctly switch to the focused workspace.
This fixes bug with moving floating windows with 'move <direction>' or by dragging like _NET_CURRENT_DESKTOP not getting updated or 'workspace back_and_forth' not working.

Fixes #2921.

@Airblader Airblader closed this in #3074 Dec 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment