Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Fix input tester in the gui for all steam deck controls #93

Open
wants to merge 9 commits into
base: python3
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ appimage/
*.cpp
*.vdf
.kateconfig
*.kdev4

dist/
sccontroller.egg-info/
114 changes: 99 additions & 15 deletions images/controller-images/deck.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 4 additions & 8 deletions scc/drivers/steamdeck.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ def _on_input(self, endpoint, data):
self.daemon.add_controller(self)
self.configure()
self._ready = True

# Don't like this version
#self._old_state, self._input = self._input, self._old_state

self._old_state, self._input = self._input, self._old_state
ctypes.memmove(ctypes.addressof(self._input), data, len(data))
if self._input.seq % UNLIZARD_INTERVAL == 0:
# Keeps lizard mode from happening
Expand Down Expand Up @@ -222,16 +221,13 @@ def _on_input(self, endpoint, data):
self._input.stick_y = apply_deadzone(self._input.stick_y, STICK_DEADZONE)
self._input.rstick_x = apply_deadzone(self._input.rstick_x, STICK_DEADZONE)
self._input.rstick_y = apply_deadzone(self._input.rstick_y, STICK_DEADZONE)

# Invert Gyro Roll to match Steam Controller coordinate system
self._input.groll = -self._input.groll

m = self.get_mapper()
if m:
self.mapper.input(self, self._old_state, self._input)

# Preserve current state into previous state object
self._old_state = self._input

def close(self):
if self._ready:
Expand Down
45 changes: 37 additions & 8 deletions scc/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from scc.gui.ribar import RIBar
from scc.tools import check_access, find_gksudo, profile_is_override, nameof
from scc.tools import get_profile_name, profile_is_default, find_profile
from scc.constants import SCButtons, STICK, STICK_PAD_MAX
from scc.constants import SCButtons, STICK, RSTICK, STICK_PAD_MAX
from scc.constants import DAEMON_VERSION, LEFT, RIGHT
from scc.paths import get_config_path, get_profiles_path
from scc.custom import load_custom_module
Expand Down Expand Up @@ -135,10 +135,14 @@ def setup_widgets(self):
self.lpad_test = Gtk.Image.new_from_file(os.path.join(self.imagepath, "test-cursor.svg"))
self.rpad_test = Gtk.Image.new_from_file(os.path.join(self.imagepath, "test-cursor.svg"))
self.stick_test = Gtk.Image.new_from_file(os.path.join(self.imagepath, "test-cursor.svg"))
self.rstick_test = Gtk.Image.new_from_file(os.path.join(self.imagepath, "test-cursor.svg"))
self.dpad_test = Gtk.Image.new_from_file(os.path.join(self.imagepath, "test-cursor.svg"))
self.main_area.put(self.lpad_test, 40, 40)
self.main_area.put(self.rpad_test, 290, 90)
self.main_area.put(self.stick_test, 150, 40)

self.main_area.put(self.rstick_test, 290, 40)
self.main_area.put(self.dpad_test, 38, 78)

# OSD mode (if used)
if self.osd_mode:
self.builder.get_object("btDaemon").set_sensitive(False)
Expand Down Expand Up @@ -992,16 +996,16 @@ def enable_test_mode(self):
if self.test_mode_controller:
self.test_mode_controller.unlock_all()
try:
c = self.dm.get_controllers()[0]
c = self.profile_switchers[0].get_controller()
except IndexError:
# Zero controllers
return
if c:
c.unlock_all()
c.observe(DaemonManager.nocallback, self.on_observe_failed,
'A', 'B', 'C', 'X', 'Y', 'START', 'BACK', 'LB', 'RB',
'LPAD', 'RPAD', 'LGRIP', 'RGRIP', 'LT', 'RT', 'LEFT',
'RIGHT', 'STICK', 'STICKPRESS')
'A', 'B', 'C', 'X', 'Y', 'START', 'BACK', 'DOTS', 'LB', 'RB',
'LPAD', 'RPAD', 'LGRIP', 'LGRIP2', 'RGRIP', 'RGRIP2', 'LT', 'RT', 'LEFT',
'RIGHT', 'STICK', 'STICKPRESS', 'RSTICK', 'RSTICKPRESS', 'DPAD')
self.test_mode_controller = c


Expand Down Expand Up @@ -1108,11 +1112,12 @@ def on_daemon_error(self, daemon, error):
def on_daemon_event_observer(self, daemon, c, what, data):
if self.osd_mode_mapper:
self.osd_mode_mapper.handle_event(daemon, what, data)
elif what in (LEFT, RIGHT, STICK):
elif what in (LEFT, RIGHT, STICK, RSTICK):
widget, area = {
LEFT : (self.lpad_test, "LPADTEST"),
RIGHT : (self.rpad_test, "RPADTEST"),
STICK : (self.stick_test, "STICKTEST"),
RSTICK : (self.rstick_test, "RSTICKTEST"),
}[what]
# Check if stick or pad is released
if data[0] == data[1] == 0:
Expand All @@ -1130,12 +1135,36 @@ def on_daemon_event_observer(self, daemon, c, what, data):
y -= data[1] * aw / STICK_PAD_MAX * 0.5
# Move circle
self.main_area.move(widget, x, y)
elif what in ("LT", "RT", "STICKPRESS"):
elif what in ("LT", "RT", "STICKPRESS", "RSTICKPRESS"):
if data[0]:
self.hilights[App.OBSERVE_COLOR].add(what)
else:
self.hilights[App.OBSERVE_COLOR].remove(what)
self._update_background()
elif what == "DPAD":
if data[0] == 0 and data[1] == 0:
self.dpad_test.hide()
else:
ax, ay, aw, ah = self.background.get_area_position("DPADTEST")
cw = self.dpad_test.get_allocation().width
ch = self.dpad_test.get_allocation().height

pos_left = [ax , ay + ah/2 - ch/2]
pos_right = [ax + aw - cw , ay + ah/2 - ch/2]
pos_top = [ax + aw/2 - cw/2, ay]
pos_bottom = [ax + aw/2 - cw/2, ay + ah - ch]

if data[0] < 0:
pos = pos_left
elif data[0] > 0:
pos = pos_right
elif data[1] < 0:
pos = pos_bottom
elif data[1] > 0:
pos = pos_top

self.main_area.move(self.dpad_test, pos[0], pos[1])
self.dpad_test.show()
elif hasattr(SCButtons, what):
try:
if data[0]:
Expand Down
2 changes: 2 additions & 0 deletions scc/gui/controller_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def _fill_button_images(self, buttons):
for i in range(len(ControllerImage.BUTTONS_WITH_IMAGES)):
b = nameof(ControllerImage.BUTTONS_WITH_IMAGES[i])
if b == "DOTS":
if self.current["gui"]["background"] != "deck":
continue
# How did I managed to create this kind of special case? -_-
i = 16
path = None
Expand Down
2 changes: 1 addition & 1 deletion scc/gui/daemon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class ControllerManager(GObject.GObject):
}

DEFAULT_ICONS = [ "A", "B", "X", "Y", "BACK", "C", "START",
"LB", "RB", "LT", "RT", "STICK", "LPAD", "RPAD", "RGRIP", "LGRIP", "DOTS" ]
"LB", "RB", "LT", "RT", "STICK", "RSTICK", "LPAD", "RPAD", "RGRIP", "LGRIP", "DOTS" ]
# ^^ those are icon names

def __init__(self, daemon_manager, controller_id, controller_type):
Expand Down
6 changes: 4 additions & 2 deletions scc/gui/statusicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def __init__(self, *args, **kwargs):
StatusIcon.__init__(self, *args, **kwargs)

try:
import gi
gi.require_version('AppIndicator3', '0.1')
from gi.repository import AppIndicator3 as appindicator

self._status_active = appindicator.IndicatorStatus.ACTIVE
Expand Down Expand Up @@ -350,8 +352,8 @@ def _load_fallback(self):
for StatusIconBackend in status_icon_backends:
try:
self._status_fb = StatusIconBackend(*self._arguments[0], **self._arguments[1])
self._status_fb.connect(b"clicked", self._on_click)
self._status_fb.connect(b"notify::active", self._on_notify_active_fb)
self._status_fb.connect("clicked", self._on_click)
self._status_fb.connect("notify::active", self._on_notify_active_fb)
self._on_notify_active_fb()

log.warning("StatusIcon: Using backend %s (fallback)" % StatusIconBackend.__name__)
Expand Down
4 changes: 3 additions & 1 deletion scc/gui/svg_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, filename, init_hilighted=True):
self.size_override = None
self.image_width = 1
self.image_height = 1
self.filename = filename
self.set_image(filename)
self.image = Gtk.Image()
if init_hilighted:
Expand All @@ -58,6 +59,7 @@ def __init__(self, filename, init_hilighted=True):


def set_image(self, filename):
self.filename = filename
self.current_svg = open(filename, "r").read()
self.cache = OrderedDict()
self.areas = []
Expand Down Expand Up @@ -139,7 +141,7 @@ def get_area_position(self, area_id):
a = self.get_area(area_id)
if a:
return a.x, a.y, a.w, a.h
raise ValueError("Area '%s' not found" % (area_id, ))
raise ValueError("Area '%s' not found in '%s'" % (area_id, self.filename))


@staticmethod
Expand Down
Loading