Skip to content

Commit a29b942

Browse files
authored
Merge pull request #10 from bluesabre/wayland-support
Disable embedding for unsupported environments
2 parents dd31757 + cd92985 commit a29b942

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

po/sgt-launcher.pot

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2021-09-06 04:36-0700\n"
11+
"POT-Creation-Date: 2021-09-11 03:38-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -18,7 +18,7 @@ msgstr ""
1818
"Content-Transfer-Encoding: 8bit\n"
1919

2020
#: ../org.bluesabre.SgtLauncher.desktop.in.h:1 ../sgtlauncher/SgtLauncher.py:39
21-
#: ../sgtlauncher/SgtLauncher.py:73 ../sgtlauncher/SgtLauncher.py:348
21+
#: ../sgtlauncher/SgtLauncher.py:73 ../sgtlauncher/SgtLauncher.py:389
2222
msgid "SGT Puzzles Collection"
2323
msgstr ""
2424

@@ -51,20 +51,20 @@ msgstr ""
5151
msgid "Please wait..."
5252
msgstr ""
5353

54-
#: ../sgtlauncher/SgtLauncher.py:209
54+
#: ../sgtlauncher/SgtLauncher.py:215 ../sgtlauncher/SgtLauncher.py:235
5555
#, python-format
5656
msgid "Loading %s"
5757
msgstr ""
5858

59-
#: ../sgtlauncher/SgtLauncher.py:403
59+
#: ../sgtlauncher/SgtLauncher.py:444
6060
msgid "About"
6161
msgstr ""
6262

63-
#: ../sgtlauncher/SgtLauncher.py:404
63+
#: ../sgtlauncher/SgtLauncher.py:445
6464
msgid "Report a Bug..."
6565
msgstr ""
6666

67-
#: ../sgtlauncher/SgtLauncher.py:405
67+
#: ../sgtlauncher/SgtLauncher.py:446
6868
msgid "Quit"
6969
msgstr ""
7070

sgtlauncher/SgtLauncher.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ def set_subtitle(self, title):
200200

201201
def launch(self, title, icon_name, path):
202202
"""Launch the specified application"""
203+
if self.launcher.embeddable:
204+
self.embedded_launch(title, icon_name, path)
205+
else:
206+
self.unembedded_launch(title, icon_name, path)
207+
208+
def embedded_launch(self, title, icon_name, path):
203209
# Toggle GTK_CSD=0 to guarantee embedding
204210
csd_env = os.environ.copy()
205211
csd_env["GTK_CSD"] = "0"
@@ -218,10 +224,45 @@ def launch(self, title, icon_name, path):
218224

219225
def on_success():
220226
self.set_view("game", icon_name, title)
227+
228+
def on_error():
229+
return self.back_to_launcher()
230+
221231
self.launcher.launch(self.socket, self.game_process,
222-
on_success, self.back_to_launcher)
232+
on_success, on_error)
233+
234+
def unembedded_launch(self, title, icon_name, path):
235+
subtitle = _("Loading %s") % title
236+
237+
if os.path.isfile(icon_name):
238+
self.launching_image.set_from_file(icon_name)
239+
else:
240+
self.launching_image.set_from_icon_name(icon_name,
241+
Gtk.IconSize.DIALOG)
242+
self.launching_title.set_markup("<b>%s</b>" % title)
243+
self.set_view("loading", icon_name, subtitle)
244+
245+
def poll_process():
246+
res = GLib.SOURCE_CONTINUE
247+
if self.game_process is None:
248+
res = GLib.SOURCE_REMOVE
249+
if self.game_process.poll() is not None:
250+
res = GLib.SOURCE_REMOVE
251+
if res == GLib.SOURCE_REMOVE:
252+
self.back_to_launcher()
253+
return res
254+
255+
def launch_game():
256+
self.game_process = subprocess.Popen([path])
257+
self.hide()
258+
GLib.timeout_add(200, poll_process)
259+
return GLib.SOURCE_REMOVE
260+
261+
GLib.timeout_add(500, launch_game)
223262

224263
def back_to_launcher(self):
264+
if not self.launcher.embeddable:
265+
self.show()
225266
if self.game_process is not None:
226267
self.game_process.terminate()
227268
self.game_process = None

sgtlauncher/SgtSocketLauncher.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# You should have received a copy of the GNU General Public License along
1414
# with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
import os
1617
import struct
1718
import time
1819
import typing
@@ -34,6 +35,31 @@ def __init__(self):
3435
self.retry_timer = 0.05
3536
self.process = None
3637
self.window_id = None
38+
self.embeddable = self.get_embeddable()
39+
40+
def get_embeddable(self):
41+
override = os.environ.get("SGT_ENABLE_EMBED")
42+
if override is not None:
43+
return override == "1"
44+
45+
# Windows are not socketable under Wayland
46+
wayland = os.environ.get("WAYLAND_DISPLAY")
47+
if wayland is not None:
48+
return False
49+
50+
# Flatpak seems to block embedding (sgt-launcher#8)
51+
container = os.environ.get("container")
52+
if container is not None:
53+
if container == "flatpak":
54+
return False
55+
56+
# GNOME doesn't allow for embedded window focus (sgt-launcher#7)
57+
desktop = os.environ.get("XDG_CURRENT_DESKTOP")
58+
if desktop is not None:
59+
if "gnome" in desktop.lower():
60+
return False
61+
62+
return True
3763

3864
def launch(self, socket: "Gtk.Socket", process: "subprocess.Popen",
3965
on_success: typing.Callable[[], None],

0 commit comments

Comments
 (0)