@@ -27,9 +27,7 @@ def scancode_to_color(scancode):
2727 if scancode == 0 :
2828 return 255 , 0 , 0
2929 brightness = 255
30- r , g , b = colorsys .hsv_to_rgb (
31- (scancode % 30 ) / 30 , 0.5 , 1
32- )
30+ r , g , b = colorsys .hsv_to_rgb ((scancode % 30 ) / 30 , 0.5 , 1 )
3331 return int (r * brightness ), int (g * brightness ), int (b * brightness )
3432
3533
@@ -57,21 +55,26 @@ def sdl_thread(
5755 stop_event : threading .Event ,
5856 sub_input : Callable [[Key ], None ] = lambda * _ : None ,
5957):
60- r , g , b = colorsys .hsv_to_rgb (
61- random .random (), (random .random () + 1 ) / 2 , 1
62- )
58+ r , g , b = colorsys .hsv_to_rgb (random .random (), (random .random () + 1 ) / 2 , 1 )
6359 back_color = int (r * 255 ), int (g * 255 ), int (b * 255 )
6460
6561 sdl2 .ext .init ()
66- window = sdl2 .ext .Window ("Input" , size = (100 , 100 ), flags = sdl2 .SDL_WINDOW_RESIZABLE )
67- renderer = sdl2 .ext .Renderer (window )
62+ sdl2 .SDL_SetHint (sdl2 .SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR , b"0" )
63+ window = sdl2 .ext .Window (
64+ "Input" ,
65+ size = (150 , 150 ),
66+ # flags=sdl2.SDL_WINDOW_RESIZABLE, # icon disapears if used
67+ )
6868
6969 pkg_share = get_package_share_directory ("keyboard_event" )
7070 surface_icon = sdl2 .ext .load_img (
7171 os .path .join (pkg_share , "icons" , "gogo.png" )
7272 # "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
7373 )
74+ sdl2 .SDL_SetWindowIcon (window .window , surface_icon )
75+ renderer = sdl2 .ext .Renderer (window )
7476 window .show ()
77+
7578 surface_gogo_calm = sdl2 .ext .load_img (
7679 os .path .join (pkg_share , "icons" , "gogo.png" ),
7780 # "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
@@ -84,8 +87,6 @@ def sdl_thread(
8487 os .path .join (pkg_share , "icons" , "gogo_happy2.png" )
8588 # "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo_happy2.png"
8689 )
87- sdl2 .SDL_SetWindowIcon (window .window , surface_icon )
88-
8990 texture_gogo_calm = sdl2 .SDL_CreateTextureFromSurface (
9091 renderer .sdlrenderer , surface_gogo_calm
9192 )
@@ -95,7 +96,7 @@ def sdl_thread(
9596 texture_gogo_happy2 = sdl2 .SDL_CreateTextureFromSurface (
9697 renderer .sdlrenderer , surface_gogo_happy2
9798 )
98- dst_rect = sdl2 .SDL_Rect (0 , 0 , 100 , 100 ) # x, y, width, height
99+ dst_rect = sdl2 .SDL_Rect (0 , 0 , 150 , 150 ) # x, y, width, height
99100
100101 renderer .color = back_color
101102 renderer .clear ()
@@ -138,15 +139,17 @@ def finish():
138139 elif e .type in [
139140 sdl2 .SDL_WINDOWEVENT ,
140141 ]:
142+ sdl2 .SDL_SetWindowIcon (window .window , surface_icon )
143+ window .show ()
141144 if e .window .event in [
142145 sdl2 .SDL_WINDOWEVENT_SIZE_CHANGED ,
143146 sdl2 .SDL_WINDOWEVENT_RESIZED ,
144147 ]:
145- pass # continues to update the window to new size
148+ pass # continues to update the window to new size
146149 else :
147- continue # does nothing
150+ continue # does nothing
148151 else :
149- continue # does nothing
152+ continue # does nothing
150153
151154 renderer .color = (
152155 scancode_to_color (list (pressed .keys ())[- 1 ])
0 commit comments