wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

`wezterm start` doesn't start window on top and focused sometimes on macos

Open Lalit64 opened this issue 2 months ago • 3 comments

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

macOS

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

aerospace

WezTerm version

20251014-193657-64f2907c

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

When I use wezterm start the window doesn't start focused or on top sometimes, it is really inconsistent .

To Reproduce

  1. Install wezterm
  2. Open a couple of windows on your screen
  3. use wezterm start
  4. Try it a few times and see that wezterm doesn't start on top or focused sometimes

Configuration

-- Generated by Home Manager.
-- See https://wezfurlong.org/wezterm/

local wezterm = require 'wezterm'

  local action = wezterm.action

  local M = {
    -- general
    audible_bell = "Disabled",
    check_for_updates = false,
    enable_scroll_bar = false,
    exit_behavior = "CloseOnCleanExit",
    warn_about_missing_glyphs =  false,
    term = "xterm-256color",
    clean_exit_codes = { 130 },

    -- anims
    animation_fps = 1,

    -- cursor
    cursor_blink_ease_in = 'EaseIn',
    cursor_blink_ease_out = 'EaseOut',
    cursor_blink_rate = 700,
    default_cursor_style = "BlinkingUnderline",

    -- font
    font_size = 16.0,
    font = wezterm.font_with_fallback({
      {
        family = "CaskaydiaMono NF",
      },
      "Apple Color Emoji"
    }),
    line_height = 1.3,
    
    -- keymap
    keys = {
      { mods = "OPT", key = "LeftArrow", action = action.SendKey({ mods = "ALT", key = "b" }) },
      { mods = "OPT", key = "RightArrow", action = action.SendKey({ mods = "ALT", key = "f" }) },
      { mods = "CMD", key = "LeftArrow", action = action.SendKey({ mods = "CTRL", key = "a" }) },
      { mods = "CMD", key = "RightArrow", action = action.SendKey({ mods = "CTRL", key = "e" }) },
      { mods = "CMD", key = "Backspace", action = action.SendKey({ mods = "CTRL", key = "u" }) },
      { mods = "CMD", key = "k", action = action.Multiple { action.ClearScrollback 'ScrollbackAndViewport', action.SendKey { key = 'l', mods = 'CTRL' }, }, },
      { key = 'n', mods = 'CMD', action = action.SpawnCommandInNewWindow { cwd=wezterm.home_dir } },
      { key = 't', mods = 'CMD', action = action.SpawnCommandInNewTab { cwd=wezterm.home_dir } },
      { key = 'd', mods = 'CMD', action = action.SplitHorizontal { domain = 'CurrentPaneDomain' } },
      { key = 'd', mods = 'CMD|SHIFT', action = action.SplitVertical { domain = 'CurrentPaneDomain' } },
    },

    -- tab bar
    enable_tab_bar = true,
    hide_tab_bar_if_only_one_tab = true,
    tab_bar_at_bottom = true,
    use_fancy_tab_bar = false,
    -- try and let the tabs stretch instead of squish
    tab_max_width = 10000,

    -- perf
    scrollback_lines = 10000,

    -- term window settings
    adjust_window_size_when_changing_font_size = false,
    window_background_opacity = 0.85,
    macos_window_background_blur = 64,              -- enables blur, set strength (higher = more blur)
    window_close_confirmation = "NeverPrompt",
    window_decorations = "RESIZE | MACOS_FORCE_SQUARE_CORNERS",
    window_padding = { left = 24, right = 24, top = 24, bottom = 24, },
  }

  function tab_title(tab_info)
    local title = tab_info.tab_title
    -- if the tab title is explicitly set, take that
    if title and #title > 0 then
      return title
    end
    -- otherwise, use the title from the active pane
    -- in that tab
    return tab_info.active_pane.title
  end

  wezterm.on(
  'format-tab-title',
  function(tab, tabs, panes, config, hover, max_width)
    local title = tab_title(tab)

    return ' ' .. title .. ' '
  end
)

M.color_scheme = "Tokyo Night Moon"

return M

Expected Behavior

wezterm should start on top and focused

Logs

No response

Anything else?

No response

Lalit64 avatar Oct 25 '25 12:10 Lalit64

Ok, I have tested without aerospace and it still does the same thing.

Lalit64 avatar Oct 25 '25 12:10 Lalit64

same for me

marsjane avatar Nov 07 '25 09:11 marsjane

I had the same issue on Windows 11 and fixed it by adding the following code in my .wezterm.lua file. I don't see a reason for not working on MacOS too.

-- Force wezterm launch in the foreground
wezterm.on("gui-startup", function(cmd)
  local _, _, window = wezterm.mux.spawn_window(cmd or {})
  window:gui_window():focus()
end)

lepa22 avatar Nov 26 '25 09:11 lepa22