Skip to content

Commit b11b443

Browse files
committed
allows cycling profiles with TAB
1 parent d346c4e commit b11b443

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/wlr_layout_ui/gui.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import math
22
import os
3-
import re
43
import time
54

65
import pyglet
@@ -20,19 +19,23 @@
2019
from .utils import (
2120
Rect,
2221
compute_bounding_box,
23-
simplify_model_name,
2422
config,
2523
find_matching_mode,
2624
make_command,
25+
simplify_model_name,
2726
sorted_frequencies,
2827
sorted_resolutions,
2928
trim_rects_flip_y,
3029
)
31-
from .widgets import Button, Dropdown, HBox, Style, VBox, Widget, Spacer
32-
30+
from .widgets import Button, Dropdown, HBox, Spacer, Style, VBox, Widget
3331

3432
CONFIRM_DELAY = 20
3533

34+
KEY_RETURN = 65293
35+
KEY_ESCAPE = 65307
36+
KEY_BACKSPACE = 65288
37+
KEY_TAB = 65289
38+
3639

3740
def get_closest_match(float_list, value):
3841
return min(float_list, key=lambda x: abs(x - value))
@@ -383,24 +386,35 @@ def on_text(self, text):
383386

384387
def on_key_press(self, symbol, modifiers):
385388
if self.text_input is None:
386-
if symbol == 65293: # return
389+
if symbol == KEY_RETURN:
387390
if self.confirmation_needed:
388391
self.confirmation_needed = False
389392
self.set_current_modes_as_ref()
390393
else:
391394
self.action_save_layout()
392-
elif symbol == 65307 and self.confirmation_needed: # Escape
395+
elif symbol == KEY_ESCAPE and self.confirmation_needed:
393396
os.system(self.original_cmd)
394397
self.confirmation_needed = False
395398
self.reset_sel()
399+
elif symbol == KEY_TAB:
400+
# cycle through profiles
401+
if not self.profile_list.options:
402+
return
403+
index = self.profile_list.selected_index
404+
index += 1
405+
if index >= len(self.profile_list.options):
406+
index = 0
407+
self.profile_list.selected_index = index
408+
# load the profile
409+
self.action_load_selected_profile()
396410
else:
397411
super().on_key_press(symbol, modifiers)
398412
else:
399-
if symbol == 65288: # backspace
413+
if symbol == KEY_BACKSPACE:
400414
self.text_input = self.text_input[:-1]
401-
elif symbol == 65293: # return
415+
elif symbol == KEY_RETURN:
402416
self.validate_text_input()
403-
elif symbol == 65307: # Escape
417+
elif symbol == KEY_ESCAPE:
404418
self.text_input = None
405419

406420
def on_mouse_motion(self, x, y, dx, dy):

0 commit comments

Comments
 (0)