Skip to content

Commit ae45132

Browse files
Updated ImGui X11 implementation
1 parent 1cb2474 commit ae45132

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Imgui/src/ImGuiImplLinuxX11.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ImGuiImplLinuxX11::ImGuiImplLinuxX11(const ImGuiDiligentCreateInfo& CI,
6565
ImGuiImplDiligent{CI}
6666
{
6767

68-
auto& io = ImGui::GetIO();
68+
ImGuiIO& io = ImGui::GetIO();
6969
io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
7070

7171
io.BackendPlatformName = "Diligent-ImGuiImplLinuxX11";
@@ -84,7 +84,7 @@ void ImGuiImplLinuxX11::NewFrame(Uint32 RenderSurfaceWidth,
8484
auto now = std::chrono::high_resolution_clock::now();
8585
auto elapsed_ns = now - m_LastTimestamp;
8686
m_LastTimestamp = now;
87-
auto& io = ImGui::GetIO();
87+
ImGuiIO& io = ImGui::GetIO();
8888
io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9);
8989

9090
VERIFY(io.DisplaySize.x == 0 || io.DisplaySize.x == static_cast<float>(RenderSurfaceWidth), "io.DisplaySize.x (",
@@ -98,14 +98,14 @@ void ImGuiImplLinuxX11::NewFrame(Uint32 RenderSurfaceWidth,
9898

9999
bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event)
100100
{
101-
auto& io = ImGui::GetIO();
101+
ImGuiIO& io = ImGui::GetIO();
102102
switch (event->type)
103103
{
104104
case ButtonPress:
105105
case ButtonRelease:
106106
{
107-
bool IsPressed = event->type == ButtonPress;
108-
auto* xbe = reinterpret_cast<XButtonEvent*>(event);
107+
bool IsPressed = (event->type == ButtonPress);
108+
XButtonEvent* xbe = reinterpret_cast<XButtonEvent*>(event);
109109
switch (xbe->button)
110110
{
111111
case Button1: io.MouseDown[0] = IsPressed; break; // Left
@@ -143,7 +143,8 @@ bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event)
143143
constexpr int buff_sz = 80;
144144
char buffer[buff_sz];
145145
int num_char = XLookupString((XKeyEvent*)event, buffer, buff_sz, &keysym, 0);
146-
ImGuiKey k = ImGuiKey_None;
146+
147+
ImGuiKey k = ImGuiKey_None;
147148
switch (keysym)
148149
{
149150
// clang-format off
@@ -164,12 +165,18 @@ bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event)
164165
case XK_Escape: k = ImGuiKey_Escape; break;
165166
case XK_KP_Enter: k = ImGuiKey_Enter; break;
166167
// clang-format on
168+
169+
default:
170+
if (keysym >= 'a' && keysym <= 'z')
171+
k = static_cast<ImGuiKey>(ImGuiKey_A + (keysym - 'a'));
172+
else if (keysym >= 'A' && keysym <= 'Z')
173+
k = static_cast<ImGuiKey>(ImGuiKey_A + (keysym - 'A'));
167174
}
168175

169176
if (k != ImGuiKey_None)
170177
io.AddKeyEvent(k, IsPressed);
171178

172-
if (k == ImGuiKey_None && IsPressed)
179+
if (IsPressed)
173180
{
174181
for (int i = 0; i < num_char; ++i)
175182
io.AddInputCharacter(buffer[i]);

0 commit comments

Comments
 (0)