summarylogtreecommitdiffstats
path: root/0001-vboard.patch
blob: 75c1f8cd2d93ef377b0db5b6beaf90e9a7bc9aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
From df39a4a0546cad2fcb9b412643921ce5e5108bb2 Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Mon, 24 Mar 2025 17:47:15 +0800
Subject: [PATCH 1/8] Add grid css

set min-width for keyboard button
---
 vboard.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/vboard.py b/vboard.py
index 20cf4de..ff912d3 100644
--- a/vboard.py
+++ b/vboard.py
@@ -246,6 +246,10 @@ class VirtualKeyboard(Gtk.Window):
             padding: 5px;
         }}
 
+        #grid button {{
+            min-width: 10px;
+            padding: 1px;
+        }}
 
         """
 
-- 
2.49.0


From 35ce46228c1992b679e179256823f7c3ad1ef151 Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Mon, 24 Mar 2025 18:02:31 +0800
Subject: [PATCH 2/8] modifier key

---
 vboard.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/vboard.py b/vboard.py
index ff912d3..81d8e30 100644
--- a/vboard.py
+++ b/vboard.py
@@ -61,6 +61,7 @@ class VirtualKeyboard(Gtk.Window):
             uinput.KEY_LEFTMETA: False,
             uinput.KEY_RIGHTMETA: False
         }
+        self.modifier_buttons = {}  # Dictionary to store mapping between modifier keys and buttons
         self.colors = [
             ("Black", "0,0,0"),
             ("Red", "255,0,0"),
@@ -249,10 +250,15 @@ class VirtualKeyboard(Gtk.Window):
         #grid button {{
             min-width: 10px;
             padding: 1px;
+            background-color: transparent;
         }}
 
-        """
+        button.active-modifier {{
+            background-color: rgba(100, 100, 255, 0.5);
+            border: 1px solid rgb(173, 216, 230);
+        }}
 
+       """
         try:
             provider.load_from_data(css.encode("utf-8"))
         except GLib.GError as e:
@@ -271,6 +277,8 @@ class VirtualKeyboard(Gtk.Window):
                     button = Gtk.Button(label=key_label[:-2])
                 else:
                     button = Gtk.Button(label=key_label)
+                # Ensure all buttons start with NONE relief style
+                button.set_relief(Gtk.ReliefStyle.NONE)
                 button.connect("clicked", self.on_button_click, key_event)
 
                 if key_label == "Space": width=12
@@ -285,11 +293,19 @@ class VirtualKeyboard(Gtk.Window):
 
                 grid.attach(button, col, row_index, width, 1)
                 col += width  # Skip 4 columns for the space button
+                if key_event in self.modifiers:
+                    self.modifier_buttons[key_event] = button
 
     def on_button_click(self, widget, key_event):
         # If the key event is one of the modifiers, update its state and return.
         if key_event in self.modifiers:
             self.modifiers[key_event] = not self.modifiers[key_event]
+            if self.modifiers[key_event]:
+                widget.set_relief(Gtk.ReliefStyle.NORMAL)
+                widget.get_style_context().add_class("active-modifier")
+            else:
+                widget.set_relief(Gtk.ReliefStyle.NONE)
+                widget.get_style_context().remove_class("active-modifier")
             return
         # For a normal key, press any active modifiers.
         for mod_key, active in self.modifiers.items():
@@ -306,6 +322,8 @@ class VirtualKeyboard(Gtk.Window):
             if active:
                 self.device.emit(mod_key, 0)
                 self.modifiers[mod_key] = False
+                self.modifier_buttons[mod_key].set_relief(Gtk.ReliefStyle.NONE)
+                self.modifier_buttons[mod_key].get_style_context().remove_class("active-modifier")
 
 
     def read_settings(self):
-- 
2.49.0


From 51f2b19b8e403fff9cb0437e6aa3eb44c08d756a Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Mon, 24 Mar 2025 18:22:22 +0800
Subject: [PATCH 3/8] Add visual feedback for Shift key state and improve
 modifier key handling

---
 vboard.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 68 insertions(+), 13 deletions(-)

diff --git a/vboard.py b/vboard.py
index 81d8e30..88bf401 100644
--- a/vboard.py
+++ b/vboard.py
@@ -51,6 +51,27 @@ class VirtualKeyboard(Gtk.Window):
         self.text_color="white"
         self.read_settings()
 
+        # Dictionary for shifted characters
+        self.shift_map = {
+            "`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", 
+            "6": "^", "7": "&", "8": "*", "9": "(", "0": ")", "-": "_", "=": "+",
+            "[": "{", "]": "}", "\\": "|", ";": ":", "'": "\"", ",": "<", ".": ">", "/": "?",
+            # 
+            "a": "A", "b": "B", "c": "C", "d": "D", "e": "E", "f": "F", "g": "G",
+            "h": "H", "i": "I", "j": "J", "k": "K", "l": "L", "m": "M", "n": "N",
+            "o": "O", "p": "P", "q": "Q", "r": "R", "s": "S", "t": "T", "u": "U",
+            "v": "V", "w": "W", "x": "X", "y": "Y", "z": "Z",
+            # 
+            "A": "A", "B": "B", "C": "C", "D": "D", "E": "E", "F": "F", "G": "G",
+            "H": "H", "I": "I", "J": "J", "K": "K", "L": "L", "M": "M", "N": "N",
+            "O": "O", "P": "P", "Q": "Q", "R": "R", "S": "S", "T": "T", "U": "U",
+            "V": "V", "W": "W", "X": "X", "Y": "Y", "Z": "Z"
+        }
+        # Dictionary to store original button labels
+        self.original_labels = {}
+        # Dictionary to store button widgets for all keys (not just modifiers)
+        self.all_buttons = {}
+
         self.modifiers = {
             uinput.KEY_LEFTSHIFT: False,
             uinput.KEY_RIGHTSHIFT: False,
@@ -295,6 +316,8 @@ class VirtualKeyboard(Gtk.Window):
                 col += width  # Skip 4 columns for the space button
                 if key_event in self.modifiers:
                     self.modifier_buttons[key_event] = button
+                self.all_buttons[key_event] = button
+                self.original_labels[key_event] = key_label
 
     def on_button_click(self, widget, key_event):
         # If the key event is one of the modifiers, update its state and return.
@@ -306,24 +329,56 @@ class VirtualKeyboard(Gtk.Window):
             else:
                 widget.set_relief(Gtk.ReliefStyle.NONE)
                 widget.get_style_context().remove_class("active-modifier")
+            
+            # Update key labels when Shift is pressed or released
+            if key_event == uinput.KEY_LEFTSHIFT or key_event == uinput.KEY_RIGHTSHIFT:
+                self.update_key_labels()
+            
             return
-        # For a normal key, press any active modifiers.
+
+        # Record which modifier keys are active, then send them
+        active_modifiers = []
         for mod_key, active in self.modifiers.items():
             if active:
-                self.device.emit(mod_key, 1)
+                active_modifiers.append(mod_key)
+                self.device.emit(mod_key, 1)  # Press the modifier key
 
-        # Emit the normal key press.
-        self.device.emit(key_event, 1)
+        # Send the normal key press event
+        self.device.emit(key_event, 1)  # Press the target key
         time.sleep(0.05)
-        self.device.emit(key_event, 0)
-
-        # Release the modifiers that were active.
-        for mod_key, active in self.modifiers.items():
-            if active:
-                self.device.emit(mod_key, 0)
-                self.modifiers[mod_key] = False
-                self.modifier_buttons[mod_key].set_relief(Gtk.ReliefStyle.NONE)
-                self.modifier_buttons[mod_key].get_style_context().remove_class("active-modifier")
+        self.device.emit(key_event, 0)  # Release the target key
+
+        # Release all previously pressed modifier keys
+        for mod_key in active_modifiers:
+            self.device.emit(mod_key, 0)  # Release the modifier key
+            self.modifiers[mod_key] = False  # Reset modifier key state
+            self.modifier_buttons[mod_key].set_relief(Gtk.ReliefStyle.NONE)
+            self.modifier_buttons[mod_key].get_style_context().remove_class("active-modifier")
+        
+        # Update keyboard labels
+        if any(mod == uinput.KEY_LEFTSHIFT or mod == uinput.KEY_RIGHTSHIFT for mod in self.modifiers):
+            self.update_key_labels()
+
+
+    def update_key_labels(self):
+        """Update key labels based on modifier states"""
+        shift_active = self.modifiers[uinput.KEY_LEFTSHIFT] or self.modifiers[uinput.KEY_RIGHTSHIFT]
+        
+        # Go through all keys and update their labels
+        for key_code, button in self.all_buttons.items():
+            if key_code in self.original_labels:
+                original_label = self.original_labels[key_code]
+                
+                # Skip modifier keys and keys that don't have shift variants
+                if key_code in self.modifiers or original_label not in self.shift_map:
+                    continue
+                    
+                if shift_active:
+                    # Show shifted character
+                    button.set_label(self.shift_map[original_label])
+                else:
+                    # Show original character
+                    button.set_label(original_label)
 
 
     def read_settings(self):
-- 
2.49.0


From dccd51a0b66b2bac3f5e8d402b8891af9aaed348 Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Mon, 24 Mar 2025 19:04:31 +0800
Subject: [PATCH 4/8] Add CapsLock UI feedback and improve key handling

---
 vboard.py | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/vboard.py b/vboard.py
index 88bf401..988e3cb 100644
--- a/vboard.py
+++ b/vboard.py
@@ -320,7 +320,24 @@ class VirtualKeyboard(Gtk.Window):
                 self.original_labels[key_event] = key_label
 
     def on_button_click(self, widget, key_event):
-        # If the key event is one of the modifiers, update its state and return.
+        # Handle CapsLock key
+        if key_event == uinput.KEY_CAPSLOCK:
+            # Send CapsLock key press event
+            self.device.emit(key_event, 1)  # Press
+            time.sleep(0.05)
+            self.device.emit(key_event, 0)  # Release
+            
+            # Update UI state
+            if widget.get_relief() == Gtk.ReliefStyle.NORMAL:
+                widget.set_relief(Gtk.ReliefStyle.NONE)
+                widget.get_style_context().remove_class("active-modifier")
+            else:
+                widget.set_relief(Gtk.ReliefStyle.NORMAL)
+                widget.get_style_context().add_class("active-modifier")
+            
+            return
+            
+        # If this is a modifier key, update its state and return
         if key_event in self.modifiers:
             self.modifiers[key_event] = not self.modifiers[key_event]
             if self.modifiers[key_event]:
@@ -330,7 +347,7 @@ class VirtualKeyboard(Gtk.Window):
                 widget.set_relief(Gtk.ReliefStyle.NONE)
                 widget.get_style_context().remove_class("active-modifier")
             
-            # Update key labels when Shift is pressed or released
+            # Update key labels when Shift state changes
             if key_event == uinput.KEY_LEFTSHIFT or key_event == uinput.KEY_RIGHTSHIFT:
                 self.update_key_labels()
             
@@ -372,12 +389,18 @@ class VirtualKeyboard(Gtk.Window):
                 # Skip modifier keys and keys that don't have shift variants
                 if key_code in self.modifiers or original_label not in self.shift_map:
                     continue
-                    
-                if shift_active:
-                    # Show shifted character
+                
+                # For letters, consider both Shift and CapsLock
+                if original_label.isalpha() and len(original_label) == 1:
+                    # If Shift and CapsLock have different states, they cancel each other out
+                    if shift_active:
+                        button.set_label(self.shift_map[original_label])
+                    else:
+                        button.set_label(original_label)
+                # For non-letters (symbols, numbers), only consider Shift
+                elif shift_active:
                     button.set_label(self.shift_map[original_label])
                 else:
-                    # Show original character
                     button.set_label(original_label)
 
 
-- 
2.49.0


From 9913293bef83d432959935e817c34b4206b9825a Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Thu, 27 Mar 2025 01:59:07 +0800
Subject: [PATCH 5/8] update layout

---
 vboard.py | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/vboard.py b/vboard.py
index 988e3cb..295ac85 100644
--- a/vboard.py
+++ b/vboard.py
@@ -10,6 +10,16 @@ gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
 from gi.repository import GLib
 
+# 获取当前桌面环境
+def get_desktop_environment():
+    # 从环境变量中获取桌面环境
+    desktop_env = os.environ.get('XDG_CURRENT_DESKTOP', '')
+    if desktop_env:
+        return desktop_env.upper()
+    return ""
+
+# 桌面环境
+DESKTOP_ENV = get_desktop_environment()
 
 key_mapping = {uinput.KEY_ESC: "Esc", uinput.KEY_1: "1", uinput.KEY_2: "2", uinput.KEY_3: "3", uinput.KEY_4: "4", uinput.KEY_5: "5", uinput.KEY_6: "6",
     uinput.KEY_7: "7", uinput.KEY_8: "8", uinput.KEY_9: "9", uinput.KEY_0: "0", uinput.KEY_MINUS: "-", uinput.KEY_EQUAL: "=",
@@ -136,7 +146,7 @@ class VirtualKeyboard(Gtk.Window):
             ["Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\"],
             ["CapsLock", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "Enter"],
             ["Shift_L", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "Shift_R", "↑"],
-            ["Ctrl_L","Super_L", "Alt_L", "Space", "Alt_R", "Super_R", "Ctrl_R", "←", "→", "↓"]
+            ["Ctrl_L","Super_L", "Alt_L", "Space", "Alt_R", "Super_R", "Ctrl_R", "←", "↓", "→"]
         ]
 
         # Create each row and add it to the grid
@@ -207,49 +217,43 @@ class VirtualKeyboard(Gtk.Window):
     def apply_css (self):
         provider = Gtk.CssProvider()
 
+        # 根据桌面环境决定是否添加background-image: none;
+        gnome_specific = ""
+        if "GNOME" in DESKTOP_ENV:
+            gnome_specific = "background-image: none;"
 
         css = f"""
         headerbar {{
             background-color: rgba({self.bg_color}, {self.opacity});
-
-
+            min-height: 40px;
+            padding: 2px 4px;
         }}
 
         headerbar button{{
-            min-width: 60px;
+            min-width: 40px;
             padding: 0px;
-            border: 0px
-
-
+            margin: 0px;
+            border: 0px;
+            background-color: transparent;
+            {gnome_specific}
         }}
 
         headerbar button label{{
-        color: {self.text_color};
-
+            color: {self.text_color};
         }}
 
-
         #toplevel {{
             background-color: rgba({self.bg_color}, {self.opacity});
-
-
-
-
         }}
 
         #grid button label{{
             color: {self.text_color};
-
-
         }}
 
-
-
         button {{
             background-color: transparent;
             border: 1px solid rgb(85, 85, 85);
             color:white;
-
         }}
 
         button:hover {{
@@ -263,7 +267,6 @@ class VirtualKeyboard(Gtk.Window):
         }}
 
        #combobox button.combo  {{
-
             color: {self.text_color};
             padding: 5px;
         }}
@@ -271,6 +274,7 @@ class VirtualKeyboard(Gtk.Window):
         #grid button {{
             min-width: 10px;
             padding: 1px;
+            margin: 1px;
             background-color: transparent;
         }}
 
@@ -304,7 +308,7 @@ class VirtualKeyboard(Gtk.Window):
 
                 if key_label == "Space": width=12
                 elif key_label == "CapsLock": width=3
-                elif key_label == "Shift_R" : width=4
+                elif key_label == "Shift_R" : width=2
                 elif key_label == "Shift_L" : width=4
                 elif key_label == "Backspace": width=5
                 elif key_label == "`": width=1
@@ -437,7 +441,6 @@ class VirtualKeyboard(Gtk.Window):
         except (configparser.Error, IOError) as e:
             print(f"Warning: Could not write to config file ({e}). Changes will not be saved.")
 
-
 if __name__ == "__main__":
     win = VirtualKeyboard()
     win.connect("destroy", Gtk.main_quit)
-- 
2.49.0


From b672cf6d36033cc400e974c3addf8fcb7ec5f8ac Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Thu, 27 Mar 2025 02:11:08 +0800
Subject: [PATCH 6/8] Add ESC button to header and implement key press
 functionality

---
 vboard.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/vboard.py b/vboard.py
index 295ac85..49296ce 100644
--- a/vboard.py
+++ b/vboard.py
@@ -128,6 +128,13 @@ class VirtualKeyboard(Gtk.Window):
         self.color_combobox = Gtk.ComboBoxText()
         # Set the header bar as the titlebar of the window
         self.set_titlebar(self.header)
+        
+        # 添加ESC按钮到顶栏左侧
+        self.esc_button = Gtk.Button(label="ESC")
+        self.esc_button.connect("clicked", lambda widget: self.on_button_click(widget, uinput.KEY_ESC))
+        self.esc_button.set_name("esc-button")
+        self.header.pack_start(self.esc_button)
+        
         self.create_settings()
 
         grid = Gtk.Grid()  # Use Grid for layout
@@ -240,6 +247,7 @@ class VirtualKeyboard(Gtk.Window):
 
         headerbar button label{{
             color: {self.text_color};
+            text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
         }}
 
         #toplevel {{
@@ -283,6 +291,14 @@ class VirtualKeyboard(Gtk.Window):
             border: 1px solid rgb(173, 216, 230);
         }}
 
+        #esc-button {{
+            border: 1px solid rgb(85, 85, 85);
+        }}
+        
+        #esc-button:hover {{
+            border: 1px solid rgb(173, 216, 230);
+        }}
+
        """
         try:
             provider.load_from_data(css.encode("utf-8"))
@@ -312,6 +328,7 @@ class VirtualKeyboard(Gtk.Window):
                 elif key_label == "Shift_L" : width=4
                 elif key_label == "Backspace": width=5
                 elif key_label == "`": width=1
+                elif key_label == "Esc": width=2
                 elif key_label == "\\" : width=4
                 elif key_label == "Enter": width=5
                 else: width=2
-- 
2.49.0


From 0318fe7bb390dccd53c08cdabd0262dfc456ecb2 Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Thu, 27 Mar 2025 02:28:52 +0800
Subject: [PATCH 7/8] Refactor: headerbar

---
 vboard.py | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/vboard.py b/vboard.py
index 49296ce..b57abcf 100644
--- a/vboard.py
+++ b/vboard.py
@@ -129,12 +129,6 @@ class VirtualKeyboard(Gtk.Window):
         # Set the header bar as the titlebar of the window
         self.set_titlebar(self.header)
         
-        # 添加ESC按钮到顶栏左侧
-        self.esc_button = Gtk.Button(label="ESC")
-        self.esc_button.connect("clicked", lambda widget: self.on_button_click(widget, uinput.KEY_ESC))
-        self.esc_button.set_name("esc-button")
-        self.header.pack_start(self.esc_button)
-        
         self.create_settings()
 
         grid = Gtk.Grid()  # Use Grid for layout
@@ -162,16 +156,22 @@ class VirtualKeyboard(Gtk.Window):
 
 
     def create_settings(self):
+        # 添加ESC按钮到顶栏左侧
+        self.esc_button = Gtk.Button(label="ESC")
+        self.esc_button.connect("clicked", lambda widget: self.on_button_click(widget, uinput.KEY_ESC))
+        self.esc_button.set_name("esc-button")
+        self.header.pack_start(self.esc_button)
+        
+        # 添加右侧控制按钮
         self.create_button("☰", self.change_visibility,callbacks=1)
         self.create_button("+", self.change_opacity,True,2)
         self.create_button("-", self.change_opacity, False,2)
-        self.create_button( f"{self.opacity}")
+        self.create_button(f"{self.opacity}")
         self.color_combobox.append_text("Change Background")
         self.color_combobox.set_active(0)
         self.color_combobox.connect("changed", self.change_color)
         self.color_combobox.set_name("combobox")
-        self.header.add(self.color_combobox)
-
+        self.header.pack_end(self.color_combobox)
 
         for label, color in self.colors:
             self.color_combobox.append_text(label)
@@ -192,12 +192,15 @@ class VirtualKeyboard(Gtk.Window):
             self.opacity_btn=button
             self.opacity_btn.set_tooltip_text("opacity")
 
-        self.header.add(button)
+        button.get_style_context().add_class("header-button")
+        self.header.pack_end(button)
         self.buttons.append(button)
+        return button
 
     def change_visibility(self, widget=None):
         for button in self.buttons:
-            if button.get_label()!="☰":
+            # 跳过ESC按钮和菜单按钮
+            if button.get_label()!="☰" and button.get_name()!="esc-button":
                 button.set_visible(not button.get_visible())
         self.color_combobox.set_visible(not self.color_combobox.get_visible() )
 
@@ -247,7 +250,6 @@ class VirtualKeyboard(Gtk.Window):
 
         headerbar button label{{
             color: {self.text_color};
-            text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
         }}
 
         #toplevel {{
@@ -265,6 +267,7 @@ class VirtualKeyboard(Gtk.Window):
         }}
 
         button:hover {{
+            background-color: transparent;
             border: 1px solid rgb(173, 216, 230);
         }}
 
@@ -289,9 +292,11 @@ class VirtualKeyboard(Gtk.Window):
         button.active-modifier {{
             background-color: rgba(100, 100, 255, 0.5);
             border: 1px solid rgb(173, 216, 230);
+            {gnome_specific}
         }}
 
         #esc-button {{
+            min-width: 60px;
             border: 1px solid rgb(85, 85, 85);
         }}
         
-- 
2.49.0


From eb89d15104cfc435af0f48196bd68e7e07b81bae Mon Sep 17 00:00:00 2001
From: honjow <honjow311@gmail.com>
Date: Thu, 27 Mar 2025 03:04:49 +0800
Subject: [PATCH 8/8] feat: add window position persistence

---
 vboard.py | 58 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/vboard.py b/vboard.py
index b57abcf..4598371 100644
--- a/vboard.py
+++ b/vboard.py
@@ -51,6 +51,13 @@ class VirtualKeyboard(Gtk.Window):
         self.set_accept_focus(False)
         self.width=0
         self.height=0
+        self.pos_x=0
+        self.pos_y=0
+        self.config_pos_x=0  # 保存配置文件中的原始位置
+        self.config_pos_y=0  # 保存配置文件中的原始位置
+
+        # 设置窗口位置为无固定位置,避免窗口管理器干预
+        self.set_position(Gtk.WindowPosition.NONE)
 
         self.CONFIG_DIR = os.path.expanduser("~/.config/vboard")
         self.CONFIG_FILE = os.path.join(self.CONFIG_DIR, "settings.conf")
@@ -121,7 +128,7 @@ class VirtualKeyboard(Gtk.Window):
         ]
         if (self.width!=0):
             self.set_default_size(self.width, self.height)
-
+            
         self.header = Gtk.HeaderBar()
         self.header.set_show_close_button(True)
         self.buttons=[]
@@ -177,9 +184,12 @@ class VirtualKeyboard(Gtk.Window):
             self.color_combobox.append_text(label)
 
     def on_resize(self, widget, event):
-        self.width, self.height = self.get_size()  # Get the current size after resize
-
-
+        # 保存窗口大小和位置
+        self.width, self.height = self.get_size()
+        # 每次窗口移动时保存当前有效位置
+        x, y = self.get_position()
+        if x > 0 and y > 0:
+            self.pos_x, self.pos_y = x, y
 
     def create_button(self, label_="", callback=None, callback2=None, callbacks=0):
         button= Gtk.Button(label=label_)
@@ -443,9 +453,21 @@ class VirtualKeyboard(Gtk.Window):
                 self.bg_color = self.config.get("DEFAULT", "bg_color" )
                 self.opacity = self.config.get("DEFAULT", "opacity" )
                 self.text_color = self.config.get("DEFAULT", "text_color", fallback="white" )
-                self.width=self.config.getint("DEFAULT", "width" , fallback=0)
-                self.height=self.config.getint("DEFAULT", "height", fallback=0)
-                print(f"rgba: {self.bg_color}, {self.opacity}")
+                self.width = self.config.getint("DEFAULT", "width", fallback=0)
+                self.height = self.config.getint("DEFAULT", "height", fallback=0)
+                
+                # 读取窗口位置
+                pos_x_str = self.config.get("DEFAULT", "pos_x", fallback="0")
+                pos_y_str = self.config.get("DEFAULT", "pos_y", fallback="0")
+                try:
+                    self.pos_x = int(pos_x_str)
+                    self.pos_y = int(pos_y_str)
+                    # 保存原始配置文件中的位置
+                    self.config_pos_x = self.pos_x
+                    self.config_pos_y = self.pos_y
+                except ValueError:
+                    self.pos_x = self.config_pos_x = 0
+                    self.pos_y = self.config_pos_y = 0
 
         except configparser.Error as e:
             print(f"Warning: Could not read config file ({e}). Using default values.")
@@ -453,21 +475,35 @@ class VirtualKeyboard(Gtk.Window):
 
 
     def save_settings(self):
-
-        self.config["DEFAULT"] = {"bg_color": self.bg_color, "opacity": self.opacity, "text_color": self.text_color, "width": self.width, "height": self.height}
+        self.config["DEFAULT"] = {
+            "bg_color": self.bg_color, 
+            "opacity": self.opacity, 
+            "text_color": self.text_color, 
+            "width": self.width, 
+            "height": self.height,
+            "pos_x": str(self.pos_x),
+            "pos_y": str(self.pos_y)
+        }
 
         try:
             with open(self.CONFIG_FILE, "w") as configfile:
                 self.config.write(configfile)
+                print(f"保存设置:位置({self.pos_x}, {self.pos_y}), 大小({self.width}, {self.height})")
 
         except (configparser.Error, IOError) as e:
             print(f"Warning: Could not write to config file ({e}). Changes will not be saved.")
 
 if __name__ == "__main__":
     win = VirtualKeyboard()
+    win.connect("delete-event", lambda w, e: win.save_settings() or False)
     win.connect("destroy", Gtk.main_quit)
-    win.connect("destroy", lambda w: win.save_settings())
-    win.show_all()
     win.connect("configure-event", win.on_resize)
+    
+    # 在显示窗口前先设置位置
+    if win.config_pos_x > 0 and win.config_pos_y > 0:
+        print(f"Setting initial window position: {win.config_pos_x}, {win.config_pos_y}")
+        win.move(win.config_pos_x, win.config_pos_y)
+    
+    win.show_all()
     win.change_visibility()
     Gtk.main()
-- 
2.49.0