Skip to content

Commit da2f6b9

Browse files
feat: add hotkey to toggle top row visibility (#186)
1 parent 6dda406 commit da2f6b9

8 files changed

Lines changed: 142 additions & 3 deletions

File tree

lib/app.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,33 @@ class _MainAppState extends ConsumerState<MainApp>
233233
_setupTray();
234234
}
235235

236+
void _toggleTopRow() {
237+
final keyboardState = ref.read(keyboardProvider);
238+
final keyboardNotifier = ref.read(keyboardProvider.notifier);
239+
final newShowTopRow = !keyboardState.showTopRow;
240+
241+
keyboardNotifier.updateShowTopRow(newShowTopRow);
242+
_adjustWindowSize();
243+
_autoHideManager.showOverlay(
244+
ref,
245+
newShowTopRow ? 'Top row shown' : 'Top row hidden',
246+
newShowTopRow
247+
? const Icon(LucideIcons.chevronUp)
248+
: const Icon(LucideIcons.chevronDown),
249+
);
250+
251+
WindowController.getAll().then((controllers) {
252+
for (final controller in controllers) {
253+
if (controller.arguments == 'preferences') {
254+
controller.invokeMethod(
255+
'updateShowTopRowFromMainWindow', newShowTopRow);
256+
}
257+
}
258+
});
259+
260+
_saveAllPreferences();
261+
}
262+
236263
void _adjustOpacity(bool increase) {
237264
final appState = ref.read(appStateProvider);
238265
final prefsState = ref.read(preferencesProvider);
@@ -332,6 +359,8 @@ class _MainAppState extends ConsumerState<MainApp>
332359
enableVisibilityHotKey: appState.enableVisibilityHotKey,
333360
toggleMoveHotKey: appState.toggleMoveHotKey,
334361
enableToggleMoveHotKey: appState.enableToggleMoveHotKey,
362+
toggleTopRowHotKey: appState.toggleTopRowHotKey,
363+
enableToggleTopRowHotKey: appState.enableToggleTopRowHotKey,
335364
preferencesHotKey: appState.preferencesHotKey,
336365
enablePreferencesHotKey: appState.enablePreferencesHotKey,
337366
increaseOpacityHotKey: appState.increaseOpacityHotKey,
@@ -358,6 +387,7 @@ class _MainAppState extends ConsumerState<MainApp>
358387
ref, 'Move enabled', const Icon(LucideIcons.move));
359388
}
360389
},
390+
onToggleTopRowTriggered: _toggleTopRow,
361391
onPreferencesTriggered: () {
362392
_autoHideManager.showOverlay(
363393
ref, 'Opening Preferences', const Icon(LucideIcons.appWindow));

lib/providers/app_state_provider.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ class AppState {
1818
final HotKey? visibilityHotKey;
1919
final HotKey? autoHideHotKey;
2020
final HotKey? toggleMoveHotKey;
21+
final HotKey? toggleTopRowHotKey;
2122
final HotKey? preferencesHotKey;
2223
final HotKey? increaseOpacityHotKey;
2324
final HotKey? decreaseOpacityHotKey;
2425
final bool enableVisibilityHotKey;
2526
final bool enableAutoHideHotKey;
2627
final bool enableToggleMoveHotKey;
28+
final bool enableToggleTopRowHotKey;
2729
final bool enablePreferencesHotKey;
2830
final bool enableIncreaseOpacityHotKey;
2931
final bool enableDecreaseOpacityHotKey;
@@ -45,12 +47,14 @@ class AppState {
4547
HotKey? visibilityHotKey,
4648
HotKey? autoHideHotKey,
4749
HotKey? toggleMoveHotKey,
50+
HotKey? toggleTopRowHotKey,
4851
HotKey? preferencesHotKey,
4952
HotKey? increaseOpacityHotKey,
5053
HotKey? decreaseOpacityHotKey,
5154
this.enableVisibilityHotKey = true,
5255
this.enableAutoHideHotKey = true,
5356
this.enableToggleMoveHotKey = true,
57+
this.enableToggleTopRowHotKey = true,
5458
this.enablePreferencesHotKey = true,
5559
this.enableIncreaseOpacityHotKey = true,
5660
this.enableDecreaseOpacityHotKey = true,
@@ -70,10 +74,14 @@ class AppState {
7074
HotKey(
7175
key: PhysicalKeyboardKey.keyE,
7276
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
73-
preferencesHotKey = preferencesHotKey ??
77+
toggleTopRowHotKey = toggleTopRowHotKey ??
7478
HotKey(
7579
key: PhysicalKeyboardKey.keyR,
7680
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
81+
preferencesHotKey = preferencesHotKey ??
82+
HotKey(
83+
key: PhysicalKeyboardKey.keyT,
84+
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
7785
increaseOpacityHotKey = increaseOpacityHotKey ??
7886
HotKey(
7987
key: PhysicalKeyboardKey.arrowUp,
@@ -92,12 +100,14 @@ class AppState {
92100
HotKey? visibilityHotKey,
93101
HotKey? autoHideHotKey,
94102
HotKey? toggleMoveHotKey,
103+
HotKey? toggleTopRowHotKey,
95104
HotKey? preferencesHotKey,
96105
HotKey? increaseOpacityHotKey,
97106
HotKey? decreaseOpacityHotKey,
98107
bool? enableVisibilityHotKey,
99108
bool? enableAutoHideHotKey,
100109
bool? enableToggleMoveHotKey,
110+
bool? enableToggleTopRowHotKey,
101111
bool? enablePreferencesHotKey,
102112
bool? enableIncreaseOpacityHotKey,
103113
bool? enableDecreaseOpacityHotKey,
@@ -116,6 +126,7 @@ class AppState {
116126
visibilityHotKey: visibilityHotKey ?? this.visibilityHotKey,
117127
autoHideHotKey: autoHideHotKey ?? this.autoHideHotKey,
118128
toggleMoveHotKey: toggleMoveHotKey ?? this.toggleMoveHotKey,
129+
toggleTopRowHotKey: toggleTopRowHotKey ?? this.toggleTopRowHotKey,
119130
preferencesHotKey: preferencesHotKey ?? this.preferencesHotKey,
120131
increaseOpacityHotKey:
121132
increaseOpacityHotKey ?? this.increaseOpacityHotKey,
@@ -126,6 +137,8 @@ class AppState {
126137
enableAutoHideHotKey: enableAutoHideHotKey ?? this.enableAutoHideHotKey,
127138
enableToggleMoveHotKey:
128139
enableToggleMoveHotKey ?? this.enableToggleMoveHotKey,
140+
enableToggleTopRowHotKey:
141+
enableToggleTopRowHotKey ?? this.enableToggleTopRowHotKey,
129142
enablePreferencesHotKey:
130143
enablePreferencesHotKey ?? this.enablePreferencesHotKey,
131144
enableIncreaseOpacityHotKey:
@@ -145,12 +158,14 @@ class AppState {
145158
'visibilityHotKey': visibilityHotKey?.toJson(),
146159
'autoHideHotKey': autoHideHotKey?.toJson(),
147160
'toggleMoveHotKey': toggleMoveHotKey?.toJson(),
161+
'toggleTopRowHotKey': toggleTopRowHotKey?.toJson(),
148162
'preferencesHotKey': preferencesHotKey?.toJson(),
149163
'increaseOpacityHotKey': increaseOpacityHotKey?.toJson(),
150164
'decreaseOpacityHotKey': decreaseOpacityHotKey?.toJson(),
151165
'enableVisibilityHotKey': enableVisibilityHotKey,
152166
'enableAutoHideHotKey': enableAutoHideHotKey,
153167
'enableToggleMoveHotKey': enableToggleMoveHotKey,
168+
'enableToggleTopRowHotKey': enableToggleTopRowHotKey,
154169
'enablePreferencesHotKey': enablePreferencesHotKey,
155170
'enableIncreaseOpacityHotKey': enableIncreaseOpacityHotKey,
156171
'enableDecreaseOpacityHotKey': enableDecreaseOpacityHotKey,
@@ -175,10 +190,15 @@ class AppState {
175190
: HotKey(
176191
key: PhysicalKeyboardKey.keyE,
177192
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
193+
toggleTopRowHotKey: json['toggleTopRowHotKey'] != null
194+
? HotKey.fromJson(json['toggleTopRowHotKey'])
195+
: HotKey(
196+
key: PhysicalKeyboardKey.keyR,
197+
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
178198
preferencesHotKey: json['preferencesHotKey'] != null
179199
? HotKey.fromJson(json['preferencesHotKey'])
180200
: HotKey(
181-
key: PhysicalKeyboardKey.keyR,
201+
key: PhysicalKeyboardKey.keyT,
182202
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
183203
increaseOpacityHotKey: json['increaseOpacityHotKey'] != null
184204
? HotKey.fromJson(json['increaseOpacityHotKey'])
@@ -193,6 +213,8 @@ class AppState {
193213
enableVisibilityHotKey: json['enableVisibilityHotKey'] as bool? ?? true,
194214
enableAutoHideHotKey: json['enableAutoHideHotKey'] as bool? ?? true,
195215
enableToggleMoveHotKey: json['enableToggleMoveHotKey'] as bool? ?? true,
216+
enableToggleTopRowHotKey:
217+
json['enableToggleTopRowHotKey'] as bool? ?? true,
196218
enablePreferencesHotKey: json['enablePreferencesHotKey'] as bool? ?? true,
197219
enableIncreaseOpacityHotKey:
198220
json['enableIncreaseOpacityHotKey'] as bool? ?? true,
@@ -241,6 +263,10 @@ class AppStateNotifier extends _$AppStateNotifier {
241263
state = state.copyWith(toggleMoveHotKey: hotKey);
242264
}
243265

266+
void updateToggleTopRowHotKey(HotKey hotKey) {
267+
state = state.copyWith(toggleTopRowHotKey: hotKey);
268+
}
269+
244270
void updatePreferencesHotKey(HotKey hotKey) {
245271
state = state.copyWith(preferencesHotKey: hotKey);
246272
}
@@ -265,6 +291,10 @@ class AppStateNotifier extends _$AppStateNotifier {
265291
state = state.copyWith(enableToggleMoveHotKey: value);
266292
}
267293

294+
void updateEnableToggleTopRowHotKey(bool value) {
295+
state = state.copyWith(enableToggleTopRowHotKey: value);
296+
}
297+
268298
void updateEnablePreferencesHotKey(bool value) {
269299
state = state.copyWith(enablePreferencesHotKey: value);
270300
}

lib/screens/preferences_screen.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class _PreferencesScreenState extends ConsumerState<PreferencesScreen>
110110
await _stateService.savePreferencesState(ref.read(preferencesProvider));
111111
}
112112

113+
if (call.method == 'updateShowTopRowFromMainWindow' && mounted) {
114+
final showTopRow = call.arguments as bool;
115+
ref.read(keyboardProvider.notifier).updateShowTopRow(showTopRow);
116+
await _stateService.saveKeyboardState(ref.read(keyboardProvider));
117+
}
118+
113119
if (call.method == 'requestFocus') {
114120
await windowManager.focus();
115121
}

lib/services/hotkey_service.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class HotKeyService {
1515
required bool enableVisibilityHotKey,
1616
required HotKey? toggleMoveHotKey,
1717
required bool enableToggleMoveHotKey,
18+
required HotKey? toggleTopRowHotKey,
19+
required bool enableToggleTopRowHotKey,
1820
required HotKey? preferencesHotKey,
1921
required bool enablePreferencesHotKey,
2022
required HotKey? increaseOpacityHotKey,
@@ -25,6 +27,7 @@ class HotKeyService {
2527
required VoidCallback onAutoHideTriggered,
2628
required VoidCallback onVisibilityTriggered,
2729
required VoidCallback onToggleMoveTriggered,
30+
required VoidCallback onToggleTopRowTriggered,
2831
required VoidCallback onPreferencesTriggered,
2932
required VoidCallback onIncreaseOpacityTriggered,
3033
required VoidCallback onDecreaseOpacityTriggered,
@@ -65,6 +68,16 @@ class HotKeyService {
6568
);
6669
}
6770

71+
if (enableToggleTopRowHotKey && toggleTopRowHotKey != null) {
72+
await hotKeyManager.register(
73+
toggleTopRowHotKey,
74+
keyDownHandler: (hotKey) {
75+
_log.debug('Toggle top row hotkey triggered.');
76+
onToggleTopRowTriggered();
77+
},
78+
);
79+
}
80+
6881
if (enablePreferencesHotKey && preferencesHotKey != null) {
6982
await hotKeyManager.register(
7083
preferencesHotKey,

lib/services/method_call_handler.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ class MethodCallHandler {
289289
appNotifier.updateToggleMoveHotKey(newHotKey);
290290
await setupHotKeys();
291291

292+
case 'updateToggleTopRowHotKey':
293+
final hotKeyJson = _safeArgument<String>(call.arguments, '{}');
294+
final newHotKey = HotKey.fromJson(jsonDecode(hotKeyJson));
295+
final currentToggleTopRowHotKey =
296+
ref.read(appStateProvider).toggleTopRowHotKey;
297+
if (currentToggleTopRowHotKey != null) {
298+
await hotKeyManager.unregister(currentToggleTopRowHotKey);
299+
}
300+
appNotifier.updateToggleTopRowHotKey(newHotKey);
301+
await setupHotKeys();
302+
292303
case 'updatePreferencesHotKey':
293304
final hotKeyJson = _safeArgument<String>(call.arguments, '{}');
294305
final newHotKey = HotKey.fromJson(jsonDecode(hotKeyJson));
@@ -337,6 +348,11 @@ class MethodCallHandler {
337348
appNotifier.updateEnableToggleMoveHotKey(enabled);
338349
await setupHotKeys();
339350

351+
case 'updateEnableToggleTopRowHotKey':
352+
final enabled = _safeArgument<bool>(call.arguments, true);
353+
appNotifier.updateEnableToggleTopRowHotKey(enabled);
354+
await setupHotKeys();
355+
340356
case 'updateEnablePreferencesHotKey':
341357
final enabled = _safeArgument<bool>(call.arguments, true);
342358
appNotifier.updateEnablePreferencesHotKey(enabled);

lib/widgets/tabs/hotkeys_tab.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,32 @@ class HotKeysTab extends ConsumerWidget {
101101
),
102102
isEnabled: appState.hotKeysEnabled,
103103
),
104+
HotKeyOption(
105+
label: 'Toggle Top Row',
106+
subtitle: 'Show or hide the top number row',
107+
formattedHotKey: _formatHotKey(appState.toggleTopRowHotKey),
108+
enabled: appState.enableToggleTopRowHotKey,
109+
onToggleChanged: (value) {
110+
ref
111+
.read(appStateProvider.notifier)
112+
.updateEnableToggleTopRowHotKey(value);
113+
onUpdateMainWindow('updateEnableToggleTopRowHotKey', value);
114+
},
115+
onChangePressed: () => _showRecordHotKeyDialog(
116+
context,
117+
(value) {
118+
ref
119+
.read(appStateProvider.notifier)
120+
.updateToggleTopRowHotKey(value);
121+
onUpdateMainWindow('updateToggleTopRowHotKey', value);
122+
},
123+
appState.toggleTopRowHotKey ??
124+
HotKey(
125+
key: PhysicalKeyboardKey.keyR,
126+
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
127+
),
128+
isEnabled: appState.hotKeysEnabled,
129+
),
104130
HotKeyOption(
105131
label: 'Open Preferences',
106132
subtitle: 'Show/focus the preferences window',
@@ -122,7 +148,7 @@ class HotKeysTab extends ConsumerWidget {
122148
},
123149
appState.preferencesHotKey ??
124150
HotKey(
125-
key: PhysicalKeyboardKey.keyR,
151+
key: PhysicalKeyboardKey.keyT,
126152
modifiers: [HotKeyModifier.alt, HotKeyModifier.control]),
127153
),
128154
isEnabled: appState.hotKeysEnabled,

0 commit comments

Comments
 (0)