Skip to content

Commit bce752f

Browse files
committed
fix(Focus): refactor window focus logic
1 parent 0f80cab commit bce752f

File tree

3 files changed

+107
-232
lines changed

3 files changed

+107
-232
lines changed

core/global/launch_manager.gd

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var _persist_path: String = "/".join([_data_dir, "launcher.json"])
6464
var _persist_data: Dictionary = {"version": 1}
6565
var _ogui_window_id := 0
6666
var should_manage_overlay := true
67-
var logger := Log.get_logger("LaunchManager", Log.LEVEL.INFO)
67+
var logger := Log.get_logger("LaunchManager", Log.LEVEL.DEBUG)
6868
var _focused_app_id := 0
6969

7070

@@ -126,19 +126,6 @@ func _init() -> void:
126126
return
127127
logger.debug("Focusable apps changed from", from, "to", to)
128128
self.check_running.call_deferred()
129-
# If focusable apps has changed and the currently focused app no longer exists,
130-
# remove the manual focus
131-
const keep_app_ids := [GamescopeInstance.EXTRA_UNKNOWN_GAME_ID, GamescopeInstance.OVERLAY_GAME_ID]
132-
var baselayer_apps := _xwayland_primary.baselayer_apps
133-
var new_baselayer_apps := PackedInt64Array()
134-
for app_id in baselayer_apps:
135-
if app_id in keep_app_ids:
136-
new_baselayer_apps.push_back(app_id)
137-
continue
138-
if app_id in to:
139-
new_baselayer_apps.push_back(app_id)
140-
if new_baselayer_apps != baselayer_apps:
141-
_xwayland_primary.baselayer_apps = new_baselayer_apps
142129
_xwayland_primary.focusable_apps_updated.connect(on_focusable_apps_changed)
143130

144131
# Listen for when focusable windows change
@@ -169,7 +156,7 @@ func _init() -> void:
169156

170157
if _xwayland_ogui:
171158
logger.debug("Enabling STEAM_OVERLAY atom")
172-
_xwayland_ogui.set_overlay(_ogui_window_id, 0)
159+
_xwayland_ogui.set_overlay(_ogui_window_id, 1)
173160

174161
var on_game_state_exited := func(_to: State):
175162
# Set the gamepad profile to the global profile
@@ -225,7 +212,6 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
225212

226213
# Execute any pre-launch hooks and start the app
227214
await _execute_hooks(app, AppLifecycleHook.TYPE.PRE_LAUNCH)
228-
running_app.start()
229215

230216
# Call any hooks at different points in the app's lifecycle
231217
var on_app_state_changed := func(_from: RunningApp.STATE, to: RunningApp.STATE):
@@ -251,13 +237,17 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
251237
var focused_window := _xwayland_primary.baselayer_window
252238
if not focused_window in old_windows:
253239
return
254-
if new_windows.is_empty():
240+
if not focused_window in new_windows:
255241
_xwayland_primary.remove_baselayer_window()
256242
return
243+
# TODO: Use the most recently created window instead of just the first in the list
257244
var new_window := new_windows[0]
258245
running_app.switch_window(new_window)
259246
running_app.window_ids_changed.connect(remove_focus)
260247

248+
# Run the application
249+
running_app.start()
250+
261251
return running_app
262252

263253

@@ -619,24 +609,22 @@ func check_running() -> void:
619609
_update_pids(all_valid_windows)
620610

621611
# Update the state of all running apps
612+
var windows_with_app := PackedInt64Array()
613+
var orphan_windows := PackedInt64Array()
622614
for app in _running:
623615
var app_pids := PackedInt64Array()
624616
if app.ogui_id in ogui_id_to_pids:
625617
app_pids = ogui_id_to_pids[app.ogui_id]
626618
app.update(all_valid_windows, app_pids)
619+
windows_with_app.append_array(app.window_ids.duplicate())
627620
for app in _running_background:
628621
var app_pids := PackedInt64Array()
629622
if app.ogui_id in ogui_id_to_pids:
630623
app_pids = ogui_id_to_pids[app.ogui_id]
631624
app.update(all_valid_windows, app_pids)
625+
windows_with_app.append_array(app.window_ids.duplicate())
632626

633627
# Look for orphan windows
634-
var windows_with_app := PackedInt64Array()
635-
var orphan_windows := PackedInt64Array()
636-
for app in _running:
637-
windows_with_app.append_array(app.window_ids.duplicate())
638-
for app in _running_background:
639-
windows_with_app.append_array(app.window_ids.duplicate())
640628
for window in all_valid_windows:
641629
if window in windows_with_app:
642630
continue

0 commit comments

Comments
 (0)