Skip to content

Commit

Permalink
fix(RunningApp): focus apps by app id instead of window id
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Sep 30, 2024
1 parent 539abf9 commit 5a96942
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 149 deletions.
15 changes: 13 additions & 2 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,21 @@ func _init() -> void:
# If the app has a gamepad profile, set it
if self._current_app:
set_app_gamepad_profile(self._current_app)

_xwayland_primary.focused_app_updated.connect(on_focused_app_changed)

# Listen for when focusable apps change
var on_focusable_apps_changed := func(from: PackedInt64Array, to: PackedInt64Array):
if from == to:
return
logger.debug("Focusable apps changed from", from, "to", to)
# If focusable apps has changed and the currently focused app no longer exists,
# remove the manual focus
var baselayer_app := _xwayland_primary.baselayer_app
to.append(_xwayland_primary.focused_app)
if baselayer_app > 0 and not baselayer_app in to:
_xwayland_primary.remove_baselayer_app()
_xwayland_primary.focusable_apps_updated.connect(on_focusable_apps_changed)

# Whenever the in-game state is entered, set the gamepad profile
var on_game_state_entered := func(_from: State):
if _current_app:
Expand Down Expand Up @@ -201,7 +213,6 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
env["DISPLAY"] = _xwayland_game.name
else:
env["DISPLAY"] = ""
var display := env["DISPLAY"] as String

# Set the OGUI ID environment variable
env["OGUI_ID"] = app.name
Expand Down
16 changes: 10 additions & 6 deletions core/systems/launcher/running_app.gd
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ func update_wayland_app() -> void:
state = STATE.RUNNING
#grab_focus() # How can we grab wayland window focus?

# Update the focus state of the app
focused = is_focused()

var state_str := {
STATE.STARTED: "started",
STATE.RUNNING: "running",
Expand Down Expand Up @@ -373,7 +376,7 @@ func get_child_pids() -> PackedInt32Array:

## Returns whether or not the app can be switched to/focused
func can_focus() -> bool:
return window_id > 0
return self.app_id > 0


## Return true if the currently running app is focused
Expand All @@ -383,8 +386,8 @@ func is_focused() -> bool:
var xwayland_primary := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_PRIMARY)
if not xwayland_primary:
return false
var focused_window := xwayland_primary.focused_window
return window_id == focused_window or focused_window in window_ids
var focused_app := xwayland_primary.focused_app
return self.app_id == focused_app


## Focuses to the app's window
Expand All @@ -394,14 +397,15 @@ func grab_focus() -> void:
var xwayland_primary := gamescope.get_xwayland(gamescope.XWAYLAND_TYPE_PRIMARY)
if not xwayland_primary:
return
xwayland_primary.set_baselayer_window(window_id)
xwayland_primary.baselayer_app = self.app_id
focused = true


## Switches the app window to the given window ID. Returns an error if unable
## to switch to the window
func switch_window(win_id: int, focus: bool = true) -> int:
# Error if the window does not belong to the running app
# TODO: Look into how window switching can work with Wayland windows
if not win_id in window_ids:
return ERR_DOES_NOT_EXIST

Expand All @@ -418,6 +422,7 @@ func switch_window(win_id: int, focus: bool = true) -> int:
window_id = win_id
if focus:
grab_focus()
xwayland_primary.baselayer_window = win_id
return OK


Expand Down Expand Up @@ -446,11 +451,10 @@ func _ensure_app_id() -> void:

# Try setting the app ID on each possible Window. If they are valid windows,
# gamescope will make these windows available as focusable windows.
var app_name := launch_item.name
for window in possible_windows:
if xwayland.has_app_id(window):
continue
xwayland.set_app_id(window, window)
xwayland.set_app_id(window, self.app_id)


## Returns whether or not the window id of the running app needs to be discovered
Expand Down
59 changes: 0 additions & 59 deletions core/systems/network/unix_socket_client.gd

This file was deleted.

53 changes: 0 additions & 53 deletions core/ui/components/input_texture_rect.gd

This file was deleted.

45 changes: 27 additions & 18 deletions extensions/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ godot = { git = "https://github.com/godot-rust/gdext", branch = "master", featur
"register-docs",
] }
nix = { version = "0.29.0", features = ["term", "process"] }
once_cell = "1.19.0"
once_cell = "1.20.1"
tokio = { version = "1.39.3", features = ["full"] }
zbus = "4.4.0"
zvariant = "4.2.0"
Expand Down
2 changes: 2 additions & 0 deletions extensions/core/src/dbus/bluez/device1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ trait Device1 {
fn connect(&self) -> zbus::Result<()>;

/// ConnectProfile method
#[allow(non_snake_case)]
fn connect_profile(&self, UUID: &str) -> zbus::Result<()>;

/// Disconnect method
fn disconnect(&self) -> zbus::Result<()>;

/// DisconnectProfile method
#[allow(non_snake_case)]
fn disconnect_profile(&self, UUID: &str) -> zbus::Result<()>;

/// Pair method
Expand Down
Loading

0 comments on commit 5a96942

Please sign in to comment.