Skip to content

Commit

Permalink
sandbox: Add support for Wayland
Browse files Browse the repository at this point in the history
- use XWayland for X application if it's run in Wayland session
- run Wayland apps directly if it's run in Wayland session

Signed-off-by: Petr Lautrbach <[email protected]>
  • Loading branch information
bachradsusi committed Feb 20, 2024
1 parent d3b5678 commit 03085af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
17 changes: 16 additions & 1 deletion sandbox/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-
selinux.chcon(self.__runuserdir, self.__filecon, recursive=True)
selinux.setfscreatecon(None)

def __is_wayland_app(self):
binary = shutil.which(self.__paths[0])
if binary is None:
return "yes"
output = subprocess.run(['ldd', binary], capture_output=True)
for line in str(output.stdout, "utf-8").split('\n'):
if line.find("libwayland") != -1:
return "yes"
return "no"

def __execute(self):
try:
cmds = [SEUNSHARE, "-Z", self.__execcon]
Expand All @@ -474,14 +484,19 @@ sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-
from gi.repository import Gtk
dpi = str(Gtk.Settings.get_default().props.gtk_xft_dpi / 1024)

if os.environ.get('WAYLAND_DISPLAY') is not None:
cmds += ["-W", os.environ["WAYLAND_DISPLAY"]]

xmodmapfile = self.__homedir + "/.xmodmap"
xd = open(xmodmapfile, "w")
subprocess.Popen(["/usr/bin/xmodmap", "-pke"], stdout=xd).wait()
xd.close()

self.__setup_sandboxrc(self.__options.wm)

cmds += ["--", SANDBOXSH, self.__options.windowsize, dpi]
WN = self.__is_wayland_app()

cmds += ["--", SANDBOXSH, WN, self.__options.windowsize, dpi]
else:
cmds += ["--"] + self.__paths
return subprocess.Popen(cmds).wait()
Expand Down
36 changes: 24 additions & 12 deletions sandbox/sandboxX.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
trap "" TERM
context=`id -Z | secon -t -l -P`
export TITLE="Sandbox $context -- `grep ^#TITLE: ~/.sandboxrc | /usr/bin/cut -b8-80`"
[ -z $1 ] && export SCREENSIZE="1000x700" || export SCREENSIZE="$1"
[ -z $2 ] && export DPI="96" || export DPI="$2"
[ -z $1 ] && export WAYLAND_NATIVE="no" || export WAYLAND_NATIVE="$1"
[ -z $2 ] && export SCREENSIZE="1000x700" || export SCREENSIZE="$2"
[ -z $3 ] && export DPI="96" || export DPI="$3"
trap "exit 0" HUP

(/usr/bin/Xephyr -resizeable -title "$TITLE" -terminate -reset -screen $SCREENSIZE -dpi $DPI -nolisten tcp -displayfd 5 5>&1 2>/dev/null) | while read D; do
export DISPLAY=:$D
cat > ~/seremote << __EOF
#!/bin/sh
DISPLAY=$DISPLAY "\$@"
if [ "$WAYLAND_NATIVE" == "no" ]; then
if [ -z "$WAYLAND_DISPLAY" ]; then
DISPLAY_COMMAND='/usr/bin/Xephyr -resizeable -title "$TITLE" -terminate -screen $SCREENSIZE -dpi $DPI -nolisten tcp -displayfd 5 5>&1 2>/dev/null'
else
DISPLAY_COMMAND='/usr/bin/Xwayland -terminate -dpi $DPI -retro -geometry $SCREENSIZE -decorate -displayfd 5 5>&1 2>/dev/null'
fi
eval $DISPLAY_COMMAND | while read D; do
export DISPLAY=:$D
cat > ~/seremote << __EOF
#!/bin/bash -x
export DISPLAY=$DISPLAY
export WAYLAND_DISPLAY=$WAYLAND_DISPLAY
"\$@"
__EOF
chmod +x ~/seremote
chmod +x ~/seremote
/usr/share/sandbox/start $HOME/.sandboxrc
export EXITCODE=$?
kill -TERM 0
break
done
else
/usr/share/sandbox/start $HOME/.sandboxrc
export EXITCODE=$?
kill -TERM 0
break
done
fi
exit 0

0 comments on commit 03085af

Please sign in to comment.