Skip to content

Commit 90e11f9

Browse files
LumaerisShadowApex
authored andcommitted
feat(Bazzite): add new os
1 parent 67d30f9 commit 90e11f9

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

core/global/platform.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum PLATFORM {
4545
MANJARO,
4646
ARCH_LIKE,
4747
NIXOS,
48+
BAZZITE,
4849
}
4950

5051
var hardware_manager := load("res://core/systems/hardware/hardware_manager.tres") as HardwareManager
@@ -130,6 +131,8 @@ func _init() -> void:
130131
os = load("res://core/platform/os/manjaro.tres")
131132
if PLATFORM.NIXOS in flags:
132133
os = load("res://core/platform/os/nixos.tres")
134+
if PLATFORM.BAZZITE in flags:
135+
os = load("res://core/platform/os/bazzite.tres")
133136

134137
if os:
135138
for action in os.startup_actions:
@@ -291,6 +294,8 @@ func _read_os() -> Array[PLATFORM]:
291294
flags.append(PLATFORM.ARCH_LIKE)
292295
if os_info.id == "nixos":
293296
flags.append(PLATFORM.NIXOS)
297+
if os_info.id == "bazzite":
298+
flags.append(PLATFORM.BAZZITE)
294299

295300
return flags
296301

core/platform/os/bazzite.gd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
extends OSPlatform
2+
class_name PlatformBazzite
3+
4+
const SESSION_SELECT_PATH := "/usr/bin/steamos-session-select"
5+
6+
7+
func _init() -> void:
8+
logger.set_name("PlatformBazzite")
9+
logger.set_level(Log.LEVEL.INFO)
10+
11+
12+
func ready(root: Window) -> void:
13+
if not _has_session_switcher():
14+
logger.info("No session switcher script detected")
15+
return
16+
_add_session_switcher(root)
17+
18+
19+
## Add a button to the power menu to allow session switching
20+
func _add_session_switcher(root: Window) -> void:
21+
# Get the power menu
22+
var power_menu := root.get_tree().get_first_node_in_group("power_menu")
23+
if not power_menu:
24+
logger.warn("No power menu was found. Unable to add session switcher.")
25+
return
26+
27+
# Create a button that will perform the session switching
28+
var button_scene := load("res://core/ui/components/card_button.tscn") as PackedScene
29+
var switch_to_desktop := button_scene.instantiate() as CardButton
30+
switch_to_desktop.click_focuses = false
31+
switch_to_desktop.text = "Switch to Desktop"
32+
switch_to_desktop.pressed.connect(_switch_session.bind("desktop"))
33+
34+
# Add the buttons just above the exit button
35+
var exit_button := power_menu.exit_button as Control
36+
var container := exit_button.get_parent()
37+
container.add_child(switch_to_desktop)
38+
container.move_child(switch_to_desktop, exit_button.get_index())
39+
40+
# Coerce the focus group to recalculate the focus neighbors
41+
var focus_group := power_menu.focus_group as FocusGroup
42+
focus_group.recalculate_focus()
43+
44+
45+
## Returns true if we detect the session switching script
46+
func _has_session_switcher() -> bool:
47+
return FileAccess.file_exists(SESSION_SELECT_PATH)
48+
49+
50+
## Switch to the given session
51+
func _switch_session(name: String) -> void:
52+
var out: Array = []
53+
var code := OS.execute(SESSION_SELECT_PATH, [name], out)
54+
if code != OK:
55+
logger.error("Unable to switch sessions: " + out[0])

core/platform/os/bazzite.gd.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://b0vn3jn36wcrh

core/platform/os/bazzite.tres

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_resource type="Resource" script_class="PlatformBazzite" load_steps=3 format=3 uid="uid://b31wnwiw1qui4"]
2+
3+
[ext_resource type="Script" uid="uid://b0vn3jn36wcrh" path="res://core/platform/os/bazzite.gd" id="1_a1d0f"]
4+
[ext_resource type="Script" uid="uid://7cj1ct3adwrg" path="res://core/platform/actions/platform_action.gd" id="2_7ctbn"]
5+
6+
[resource]
7+
script = ExtResource("1_a1d0f")
8+
name = ""
9+
startup_actions = Array[ExtResource("2_7ctbn")]([])
10+
shutdown_actions = Array[ExtResource("2_7ctbn")]([])

0 commit comments

Comments
 (0)