Browse Source

X11: Fixed send modifier keys when no other keys are pressed.

Бранимир Караџић 8 months ago
parent
commit
dd49a5742d
2 changed files with 12 additions and 2 deletions
  1. 9 0
      examples/common/entry/entry_x11.cpp
  2. 3 2
      examples/common/imgui/imgui.cpp

+ 9 - 0
examples/common/entry/entry_x11.cpp

@@ -422,6 +422,8 @@ namespace entry
 				bool joystick = s_joystick.update(m_eventQueue);
 				bool xpending = XPending(m_display);
 
+				uint8_t oldModifers = m_modifiers;
+
 				if (!xpending)
 				{
 					bx::sleep(joystick ? 8 : 16);
@@ -500,6 +502,7 @@ namespace entry
 							{
 								XKeyEvent& xkey = event.xkey;
 								KeySym keysym = XLookupKeysym(&xkey, 0);
+
 								switch (keysym)
 								{
 								case XK_Meta_L:    setModifier(Modifier::LeftMeta,   KeyPress == event.type); break;
@@ -538,6 +541,7 @@ namespace entry
 										if (Key::None != key)
 										{
 											m_eventQueue.postKeyEvent(handle, key, m_modifiers, KeyPress == event.type);
+											oldModifers = m_modifiers;
 										}
 									}
 									break;
@@ -556,6 +560,11 @@ namespace entry
 							}
 							break;
 					}
+
+					if (oldModifers != m_modifiers)
+					{
+						m_eventQueue.postKeyEvent({ UINT16_MAX }, Key::None, m_modifiers, true);
+					}
 				}
 			}
 

+ 3 - 2
examples/common/imgui/imgui.cpp

@@ -471,12 +471,13 @@ struct OcornutImguiContext
 		m_lastScroll = _scroll;
 
 #if USE_ENTRY
-		uint8_t modifiers = inputGetModifiersState();
+		const uint8_t modifiers = inputGetModifiersState();
 		io.AddKeyEvent(ImGuiMod_Shift, 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) ) );
 		io.AddKeyEvent(ImGuiMod_Ctrl,  0 != (modifiers & (entry::Modifier::LeftCtrl  | entry::Modifier::RightCtrl ) ) );
 		io.AddKeyEvent(ImGuiMod_Alt,   0 != (modifiers & (entry::Modifier::LeftAlt   | entry::Modifier::RightAlt  ) ) );
 		io.AddKeyEvent(ImGuiMod_Super, 0 != (modifiers & (entry::Modifier::LeftMeta  | entry::Modifier::RightMeta ) ) );
-		for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
+
+		for (int32_t ii = 0; ii < int32_t(entry::Key::Count); ++ii)
 		{
 			io.AddKeyEvent(m_keyMap[ii], inputGetKeyState(entry::Key::Enum(ii) ) );
 			io.SetKeyEventNativeData(m_keyMap[ii], 0, 0, ii);