wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Unexpected extra window when opening a workspace in a domain.

Open Ruben-Kruepper opened this issue 2 years ago • 7 comments

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

20231030-074559-75909682

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

I have a very simple config set up to automatically open a workspace in a domain.

It works, but it has some unexpected behavior: If I switch to parsonos.lab / Parsonos Lab, then back to local / default, I suddenly also have a window open at parsonos.lab / default. This window (re)opens every time I switch back and forth.

The docs:

The wezterm GUI is focused on the active workspace, which means that it will present a GUI window for each MuxWindow that is present in that workspace.

So I wouldn't expect the default workspace to care about the parsonos.lab domain at all.

To Reproduce

My other config is cosmetic only. To reproduce: set up the config as above, then switch back and forth between workspaces using the keymaps.

Configuration

config.unix_domains = {
  {
    name = "parsonos.lab",
  },
}

config.leader = { key = "a", mods = "CTRL" }
config.keys = {
  -- Switch to the default workspace
  {
    key = "=",
    mods = "LEADER",
    action = act.SwitchToWorkspace({
      name = "default",
    }),
  },
  {
    key = "!",
    mods = "LEADER",
    action = wezterm.action({
      SwitchToWorkspace = {
        name = "Parsonos Lab",
        spawn = {
          domain = { DomainName = "parsonos.lab" },
        },
      },
    }),
  },
  -- Create a new workspace with a random name and switch to it
  { key = "i", mods = "CTRL|SHIFT", action = act.SwitchToWorkspace },
  -- Show the launcher in fuzzy selection mode and have it list all workspaces
  -- and allow activating one.
  {
    key = "*",
    mods = "LEADER",
    action = act.ShowLauncherArgs({
      flags = "FUZZY|WORKSPACES",
    }),
  },
}

Expected Behavior

I expected no window parsonos.lab / default to appear.

Logs

❯ wezterm 17:45:14.225 WARN wezterm_client::client > While connecting to Socket("/Users/ruben/.local/share/wezterm/sock"): connecting to /Users/ruben/.local/share/wezterm/sock. Will try spawning the server. 17:45:14.227 WARN wezterm_client::client > Running: "/opt/homebrew/bin/wezterm-mux-server" "--daemonize" 17:45:23.284 INFO mux > detaching domain 17:45:23.285 INFO wezterm_client::domain > detached domain 1 17:45:23.285 INFO mux > domain detached panes: [3, 2] 17:45:23.316 INFO wezterm_client::domain > detached domain 1 17:45:23.316 INFO mux > domain detached panes: []

Anything else?

No response

Ruben-Kruepper avatar Nov 03 '23 16:11 Ruben-Kruepper

I was trying to work around this issue by writing my own implementation of the behaviour I wanted, with the added benefit of more fine-grained control. However, this made the issue much worse?

local open_default_workspace = wezterm.action_callback(function(window, pane)
	mux.set_active_workspace("default")
end)

local open_lab_workspace = wezterm.action_callback(function(window, pane)
	if pcall(mux.set_active_workspace, "parsonos-lab") then
		return
	end
	local project_dir = "parsonos-lab"
	local tab, build_pane, window = mux.spawn_window({
		workspace = "parsonos-lab",
		cwd = project_dir,
		domain = { DomainName = "parsonos.lab" },
	})
	local editor_pane = build_pane:split({
		direction = "Top",
		size = 0.8,
		cwd = project_dir,
		domain = { DomainName = "parsonos.lab" },
	})
	editor_pane:send_text("nvim .\n")
	mux.set_active_workspace("parsonos-lab")
end)

Now, every time I switch back to default from lab, I get increasingly more windows in default with a domain of parsonos.lab. Half of them share the pane setup from the open_lab_workspace, except the split has different proportions. Finally, when I close any one of the "extra" windows, all of them close.

Hope this helps!

Ruben-Kruepper avatar Nov 03 '23 18:11 Ruben-Kruepper

Can you minimize the steps that reproduce this? What I'd like to see is a precise/deterministic set of steps (so, avoid instructions like "try switching back and forth"), and what would be helpful is seeing the output from wezterm cli list --format json from before and after the critical step that triggers the misbehavior.

Thank you!

wez avatar Nov 04 '23 13:11 wez

Ok, I simplified this as far as I could. 😅 Here goes:

local wezterm = require("wezterm")
local act = wezterm.action
local mux = wezterm.mux

local config = wezterm.config_builder()

wezterm.on("update-status", function(window, pane)
	window:set_left_status(wezterm.format({
		{ Foreground = { AnsiColor = "Red" } },
		{ Text = "  " .. window:active_workspace() .. " / " .. pane:get_domain_name() .. "  " },
	}))
end)

config.unix_domains = {
	{
		name = "parsonos.lab",
	},
}

config.keys = {
	-- Switch to the default workspace
	{
		key = "1",
		mods = "CTRL",
		action = act.SwitchToWorkspace({
			name = "default",
		}),
	},
	{
		key = "2",
		mods = "CTRL",
		action = wezterm.action({
			SwitchToWorkspace = {
				name = "Parsonos Lab",
				spawn = {
					domain = { DomainName = "parsonos.lab" },
				},
			},
		}),
	},
}

return config
  1. Open Wezterm. Status shows default / local as expected
  2. Hit CTRL-2. After a short lag of starting up domain, the window is exchanged with Parsonos Lab / parsonos.lab as expected
  3. Hit CTRL-1. GUI instantly switches to two windows. One is default / local as expected, the other is default / parsonos.lab (unexpected!)
  4. Bonus: Hit CTRL-2 again. If you did not close the extra default / parsonos.lab window, then it just switches Parsonos Lab / parsonos.lab as expected. If you did close the extra default / parsonos.lab window, then a new tab is opened (the old ones are still there), running the default command.

Additional observation: The unexpected extra window appears at random locations whenever switching back to default.

Cheers! 🍻

Ruben-Kruepper avatar Nov 04 '23 21:11 Ruben-Kruepper

The even weirder behaviour from my attempted workaround still stands, it follows the same pattern. It just spawns more "extra" windows, which close all together when any one is closed.

Ruben-Kruepper avatar Nov 04 '23 21:11 Ruben-Kruepper

Please also include the wezterm cli list --format json output from before and after the critical step

wez avatar Nov 04 '23 23:11 wez

After clean startup (restarted mux as well):

[
  {
    "window_id": 0,
    "tab_id": 0,
    "pane_id": 0,
    "workspace": "default",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1120,
      "pixel_height": 768,
      "dpi": 144
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 0,
    "cursor_y": 1,
    "cursor_shape": "Default",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": "/dev/ttys000"
  }
]

After first step out to Parsonos Lab / parsonos.lab

[
  {
    "window_id": 0,
    "tab_id": 0,
    "pane_id": 0,
    "workspace": "default",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 640,
      "pixel_height": 384,
      "dpi": 0
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 3,
    "cursor_y": 1,
    "cursor_shape": "SteadyBar",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": "/dev/ttys001"
  },
  {
    "window_id": 1,
    "tab_id": 1,
    "pane_id": 1,
    "workspace": "Parsonos Lab",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1120,
      "pixel_height": 768,
      "dpi": 144
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 0,
    "cursor_y": 1,
    "cursor_shape": "Default",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": "/dev/ttys002"
  }
]

After switching back to default:

[
  {
    "window_id": 2,
    "tab_id": 2,
    "pane_id": 2,
    "workspace": "default",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1120,
      "pixel_height": 768,
      "dpi": 144
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 3,
    "cursor_y": 1,
    "cursor_shape": "SteadyBar",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": null
  },
  {
    "window_id": 1,
    "tab_id": 3,
    "pane_id": 3,
    "workspace": "Parsonos Lab",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1120,
      "pixel_height": 768,
      "dpi": 144
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 3,
    "cursor_y": 23,
    "cursor_shape": "SteadyBar",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": null
  },
  {
    "window_id": 0,
    "tab_id": 0,
    "pane_id": 0,
    "workspace": "default",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1120,
      "pixel_height": 768,
      "dpi": 144
    },
    "title": "zsh",
    "cwd": "file://rubens-macbook-air.local/Users/ruben",
    "cursor_x": 0,
    "cursor_y": 22,
    "cursor_shape": "Default",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0,
    "tab_title": "",
    "window_title": "",
    "is_active": true,
    "is_zoomed": false,
    "tty_name": "/dev/ttys000"
  }
]

Ruben-Kruepper avatar Nov 05 '23 10:11 Ruben-Kruepper

I noticed the same issue with my workspace sessionizer script on my Linux machine running X11 and i3.

Every new workspace switch would create what would register as a separate window in the background (that i3 couldn't manage).

laulauland avatar Feb 19 '24 06:02 laulauland