summaryrefslogtreecommitdiffstats
path: root/tools/platform/linux
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /tools/platform/linux
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'tools/platform/linux')
-rw-r--r--tools/platform/linux/x11-key-code.cpp380
-rw-r--r--tools/platform/linux/x11-window.cpp223
2 files changed, 316 insertions, 287 deletions
diff --git a/tools/platform/linux/x11-key-code.cpp b/tools/platform/linux/x11-key-code.cpp
index c078a6d1c..0faafae78 100644
--- a/tools/platform/linux/x11-key-code.cpp
+++ b/tools/platform/linux/x11-key-code.cpp
@@ -1,9 +1,10 @@
#if defined(SLANG_ENABLE_XLIB)
-#include "core/slang-basic.h"
#include "../window.h"
-#include <X11/keysym.h>
+#include "core/slang-basic.h"
+
#include <X11/Xlib.h>
+#include <X11/keysym.h>
#ifdef None
#undef None
@@ -15,233 +16,196 @@ using namespace Slang;
namespace platform
{
- Dictionary<int, KeyCode> keyCodeMap;
+Dictionary<int, KeyCode> keyCodeMap;
- struct Win32KeyCode
- {
- KeyCode vKeyCode;
- int keySym;
- };
+struct Win32KeyCode
+{
+ KeyCode vKeyCode;
+ int keySym;
+};
- Win32KeyCode keys[] =
- {
- {KeyCode::Left, XK_Left},
- {KeyCode::Up, XK_Up},
- {KeyCode::Down, XK_Down},
- {KeyCode::Right, XK_Right},
- {KeyCode::Escape, XK_Escape},
- {KeyCode::Return, XK_Return},
- {KeyCode::Space, XK_space},
- {KeyCode::Shift, XK_Shift_L},
- {KeyCode::Shift, XK_Shift_R},
- {KeyCode::Ctrl, XK_Control_L},
- {KeyCode::Ctrl, XK_Control_R},
- {KeyCode::Alt, XK_Alt_L},
- {KeyCode::Alt, XK_Alt_R},
- {KeyCode::Backspace, XK_BackSpace},
- {KeyCode::Delete, XK_Delete},
- {KeyCode::Home, XK_Home},
- {KeyCode::End, XK_End},
- {KeyCode::PageUp, XK_Page_Up},
- {KeyCode::PageDown, XK_Page_Down},
- {KeyCode::Insert, XK_Insert},
- {KeyCode::Tab, XK_Tab},
- {KeyCode::A, 0x41},
- {KeyCode::B, 0x42},
- {KeyCode::C, 0x43},
- {KeyCode::D, 0x44},
- {KeyCode::E, 0x45},
- {KeyCode::F, 0x46},
- {KeyCode::G, 0x47},
- {KeyCode::H, 0x48},
- {KeyCode::I, 0x49},
- {KeyCode::J, 0x4A},
- {KeyCode::K, 0x4B},
- {KeyCode::L, 0x4C},
- {KeyCode::M, 0x4D},
- {KeyCode::N, 0x4E},
- {KeyCode::O, 0x4F},
- {KeyCode::P, 0x50},
- {KeyCode::Q, 0x51},
- {KeyCode::R, 0x52},
- {KeyCode::S, 0x53},
- {KeyCode::T, 0x54},
- {KeyCode::U, 0x55},
- {KeyCode::V, 0x56},
- {KeyCode::W, 0x57},
- {KeyCode::X, 0x58},
- {KeyCode::Y, 0x59},
- {KeyCode::Z, 0x5A},
- {KeyCode::Semicolon, XK_semicolon},
- {KeyCode::Comma, XK_comma},
- {KeyCode::Dot, XK_period},
- {KeyCode::Slash, XK_slash},
- {KeyCode::Quote, XK_apostrophe},
- {KeyCode::LBracket, XK_bracketleft},
- {KeyCode::RBracket, XK_bracketright},
- {KeyCode::Backslash, XK_backslash},
- {KeyCode::Minus, XK_minus},
- {KeyCode::Plus, XK_equal},
- {KeyCode::Tilde, XK_asciitilde},
- {KeyCode::Key0, 0x30},
- {KeyCode::Key1, 0x31},
- {KeyCode::Key2, 0x32},
- {KeyCode::Key3, 0x33},
- {KeyCode::Key4, 0x34},
- {KeyCode::Key5, 0x35},
- {KeyCode::Key6, 0x36},
- {KeyCode::Key7, 0x37},
- {KeyCode::Key8, 0x38},
- {KeyCode::Key9, 0x39},
- {KeyCode::F1, XK_F1},
- {KeyCode::F2, XK_F2},
- {KeyCode::F3, XK_F3},
- {KeyCode::F4, XK_F4},
- {KeyCode::F5, XK_F5},
- {KeyCode::F6, XK_F6},
- {KeyCode::F7, XK_F7},
- {KeyCode::F8, XK_F8},
- {KeyCode::F9, XK_F9},
- {KeyCode::F10, XK_F10},
- {KeyCode::F11, XK_F11},
- {KeyCode::F12, XK_F12}
- };
+Win32KeyCode keys[] = {
+ {KeyCode::Left, XK_Left},
+ {KeyCode::Up, XK_Up},
+ {KeyCode::Down, XK_Down},
+ {KeyCode::Right, XK_Right},
+ {KeyCode::Escape, XK_Escape},
+ {KeyCode::Return, XK_Return},
+ {KeyCode::Space, XK_space},
+ {KeyCode::Shift, XK_Shift_L},
+ {KeyCode::Shift, XK_Shift_R},
+ {KeyCode::Ctrl, XK_Control_L},
+ {KeyCode::Ctrl, XK_Control_R},
+ {KeyCode::Alt, XK_Alt_L},
+ {KeyCode::Alt, XK_Alt_R},
+ {KeyCode::Backspace, XK_BackSpace},
+ {KeyCode::Delete, XK_Delete},
+ {KeyCode::Home, XK_Home},
+ {KeyCode::End, XK_End},
+ {KeyCode::PageUp, XK_Page_Up},
+ {KeyCode::PageDown, XK_Page_Down},
+ {KeyCode::Insert, XK_Insert},
+ {KeyCode::Tab, XK_Tab},
+ {KeyCode::A, 0x41},
+ {KeyCode::B, 0x42},
+ {KeyCode::C, 0x43},
+ {KeyCode::D, 0x44},
+ {KeyCode::E, 0x45},
+ {KeyCode::F, 0x46},
+ {KeyCode::G, 0x47},
+ {KeyCode::H, 0x48},
+ {KeyCode::I, 0x49},
+ {KeyCode::J, 0x4A},
+ {KeyCode::K, 0x4B},
+ {KeyCode::L, 0x4C},
+ {KeyCode::M, 0x4D},
+ {KeyCode::N, 0x4E},
+ {KeyCode::O, 0x4F},
+ {KeyCode::P, 0x50},
+ {KeyCode::Q, 0x51},
+ {KeyCode::R, 0x52},
+ {KeyCode::S, 0x53},
+ {KeyCode::T, 0x54},
+ {KeyCode::U, 0x55},
+ {KeyCode::V, 0x56},
+ {KeyCode::W, 0x57},
+ {KeyCode::X, 0x58},
+ {KeyCode::Y, 0x59},
+ {KeyCode::Z, 0x5A},
+ {KeyCode::Semicolon, XK_semicolon},
+ {KeyCode::Comma, XK_comma},
+ {KeyCode::Dot, XK_period},
+ {KeyCode::Slash, XK_slash},
+ {KeyCode::Quote, XK_apostrophe},
+ {KeyCode::LBracket, XK_bracketleft},
+ {KeyCode::RBracket, XK_bracketright},
+ {KeyCode::Backslash, XK_backslash},
+ {KeyCode::Minus, XK_minus},
+ {KeyCode::Plus, XK_equal},
+ {KeyCode::Tilde, XK_asciitilde},
+ {KeyCode::Key0, 0x30},
+ {KeyCode::Key1, 0x31},
+ {KeyCode::Key2, 0x32},
+ {KeyCode::Key3, 0x33},
+ {KeyCode::Key4, 0x34},
+ {KeyCode::Key5, 0x35},
+ {KeyCode::Key6, 0x36},
+ {KeyCode::Key7, 0x37},
+ {KeyCode::Key8, 0x38},
+ {KeyCode::Key9, 0x39},
+ {KeyCode::F1, XK_F1},
+ {KeyCode::F2, XK_F2},
+ {KeyCode::F3, XK_F3},
+ {KeyCode::F4, XK_F4},
+ {KeyCode::F5, XK_F5},
+ {KeyCode::F6, XK_F6},
+ {KeyCode::F7, XK_F7},
+ {KeyCode::F8, XK_F8},
+ {KeyCode::F9, XK_F9},
+ {KeyCode::F10, XK_F10},
+ {KeyCode::F11, XK_F11},
+ {KeyCode::F12, XK_F12}};
- void initKeyCodeTranslationTable(Display* display)
+void initKeyCodeTranslationTable(Display* display)
+{
+ for (auto entry : keys)
{
- for (auto entry : keys)
- {
- auto systemKeyCode = XKeysymToKeycode(display, entry.keySym);
- keyCodeMap[systemKeyCode] = entry.vKeyCode;
- }
+ auto systemKeyCode = XKeysymToKeycode(display, entry.keySym);
+ keyCodeMap[systemKeyCode] = entry.vKeyCode;
}
+}
- void freeKeyCodeTranslationTable()
+void freeKeyCodeTranslationTable()
+{
+ keyCodeMap = decltype(keyCodeMap)();
+}
+
+KeyCode translateKeyCode(int keyCode)
+{
+ KeyCode result = KeyCode::None;
+ keyCodeMap.tryGetValue(keyCode, result);
+ return result;
+}
+
+int getKeyChar(KeyCode keyCode, int keyState)
+{
+ bool shift = (keyState & ShiftMask) != 0;
+ if (keyCode >= KeyCode::A && keyCode <= KeyCode::Z)
{
- keyCodeMap = decltype(keyCodeMap)();
+ bool capslock = (keyState & LockMask) != 0;
+ bool isCapital = capslock ^ shift;
+ if (isCapital)
+ return (int)keyCode;
+ else
+ return (int)keyCode + ('a' - 'A');
}
-
- KeyCode translateKeyCode(int keyCode)
+ else if (keyCode == KeyCode::Space)
{
- KeyCode result = KeyCode::None;
- keyCodeMap.tryGetValue(keyCode, result);
- return result;
+ return ' ';
}
-
- int getKeyChar(KeyCode keyCode, int keyState)
+ else if (keyCode == KeyCode::Return)
{
- bool shift = (keyState & ShiftMask) != 0;
- if (keyCode >= KeyCode::A && keyCode <= KeyCode::Z )
- {
- bool capslock = (keyState & LockMask) != 0;
- bool isCapital = capslock ^ shift;
- if (isCapital)
- return (int)keyCode;
- else
- return (int)keyCode + ('a'-'A');
- }
- else if (keyCode == KeyCode::Space)
- {
- return ' ';
- }
- else if (keyCode == KeyCode::Return)
- {
+ return (int)keyCode;
+ }
+ else if (keyCode >= KeyCode::Key0 && keyCode <= KeyCode::Key9)
+ {
+ if (!shift)
return (int)keyCode;
- }
- else if (keyCode >= KeyCode::Key0 && keyCode <= KeyCode::Key9)
+ else
{
- if (!shift)
- return (int)keyCode;
- else
+ switch (keyCode)
{
- switch (keyCode)
- {
- case KeyCode::Key0:
- return ')';
- case KeyCode::Key1:
- return '!';
- case KeyCode::Key2:
- return '@';
- case KeyCode::Key3:
- return '#';
- case KeyCode::Key4:
- return '$';
- case KeyCode::Key5:
- return '%';
- case KeyCode::Key6:
- return '^';
- case KeyCode::Key7:
- return '&';
- case KeyCode::Key8:
- return '*';
- case KeyCode::Key9:
- return '(';
- default:
- return 0;
- }
+ case KeyCode::Key0: return ')';
+ case KeyCode::Key1: return '!';
+ case KeyCode::Key2: return '@';
+ case KeyCode::Key3: return '#';
+ case KeyCode::Key4: return '$';
+ case KeyCode::Key5: return '%';
+ case KeyCode::Key6: return '^';
+ case KeyCode::Key7: return '&';
+ case KeyCode::Key8: return '*';
+ case KeyCode::Key9: return '(';
+ default: return 0;
}
}
- if (shift)
+ }
+ if (shift)
+ {
+ switch (keyCode)
{
- switch (keyCode)
- {
- case KeyCode::Semicolon:
- return ':';
- case KeyCode::Comma:
- return '<';
- case KeyCode::Dot:
- return '>';
- case KeyCode::Slash:
- return '?';
- case KeyCode::Quote:
- return '\"';
- case KeyCode::LBracket:
- return '{';
- case KeyCode::RBracket:
- return '}';
- case KeyCode::Backslash:
- return '|';
- case KeyCode::Minus:
- return '_';
- case KeyCode::Plus:
- return '+';
- case KeyCode::Tilde:
- return '~';
- default:
- return 0;
- }
+ case KeyCode::Semicolon: return ':';
+ case KeyCode::Comma: return '<';
+ case KeyCode::Dot: return '>';
+ case KeyCode::Slash: return '?';
+ case KeyCode::Quote: return '\"';
+ case KeyCode::LBracket: return '{';
+ case KeyCode::RBracket: return '}';
+ case KeyCode::Backslash: return '|';
+ case KeyCode::Minus: return '_';
+ case KeyCode::Plus: return '+';
+ case KeyCode::Tilde: return '~';
+ default: return 0;
}
- else
+ }
+ else
+ {
+ switch (keyCode)
{
- switch (keyCode)
- {
- case KeyCode::Semicolon:
- return ';';
- case KeyCode::Comma:
- return ',';
- case KeyCode::Dot:
- return '.';
- case KeyCode::Slash:
- return '/';
- case KeyCode::Quote:
- return '\'';
- case KeyCode::LBracket:
- return '[';
- case KeyCode::RBracket:
- return ']';
- case KeyCode::Backslash:
- return '\\';
- case KeyCode::Minus:
- return '-';
- case KeyCode::Plus:
- return '=';
- case KeyCode::Tilde:
- return '`';
- default:
- return 0;
- }
+ case KeyCode::Semicolon: return ';';
+ case KeyCode::Comma: return ',';
+ case KeyCode::Dot: return '.';
+ case KeyCode::Slash: return '/';
+ case KeyCode::Quote: return '\'';
+ case KeyCode::LBracket: return '[';
+ case KeyCode::RBracket: return ']';
+ case KeyCode::Backslash: return '\\';
+ case KeyCode::Minus: return '-';
+ case KeyCode::Plus: return '=';
+ case KeyCode::Tilde: return '`';
+ default: return 0;
}
}
+}
} // namespace platform
#endif
diff --git a/tools/platform/linux/x11-window.cpp b/tools/platform/linux/x11-window.cpp
index be807ac33..155801049 100644
--- a/tools/platform/linux/x11-window.cpp
+++ b/tools/platform/linux/x11-window.cpp
@@ -1,9 +1,10 @@
#ifdef SLANG_ENABLE_XLIB
#include "../window.h"
+
#include <X11/Xlib.h>
-#include <X11/Xutil.h>
#include <X11/Xresource.h>
+#include <X11/Xutil.h>
#ifdef None
#undef None
@@ -18,7 +19,7 @@ namespace platform
typedef ::Window X11WindowHandle;
class X11PlatformWindow;
-void initKeyCodeTranslationTable(Display *display);
+void initKeyCodeTranslationTable(Display* display);
void freeKeyCodeTranslationTable();
KeyCode translateKeyCode(int keyCode);
int getKeyChar(KeyCode keyCode, int keyState);
@@ -34,12 +35,16 @@ enum class KeyState
enum class KeyEvent
{
- Press, Release
+ Press,
+ Release
};
enum class MouseEvent
{
- Move, Down, Up, Scroll
+ Move,
+ Down,
+ Up,
+ Scroll
};
class X11AppContext
@@ -51,7 +56,7 @@ public:
static X11WindowHandle mainWindowHandle;
static Display* xdisplay;
static KeyState keyStates[kKeyStateTableSize];
- static X11PlatformWindow *currentMouseEventWindow;
+ static X11PlatformWindow* currentMouseEventWindow;
};
bool X11AppContext::isTerminated = false;
@@ -62,16 +67,19 @@ Display* X11AppContext::xdisplay = nullptr;
KeyState X11AppContext::keyStates[kKeyStateTableSize] = {};
X11PlatformWindow* X11AppContext::currentMouseEventWindow = nullptr;
-void Application::init()
-{
-
-}
+void Application::init() {}
static void doEventsImpl(bool waitForEvents);
-void Application::doEvents() { doEventsImpl(false); }
+void Application::doEvents()
+{
+ doEventsImpl(false);
+}
-void Application::quit() { X11AppContext::isTerminated = true; }
+void Application::quit()
+{
+ X11AppContext::isTerminated = true;
+}
void Application::dispose()
{
@@ -85,7 +93,8 @@ void Application::run(Window* mainWindow, bool waitForEvents)
if (mainWindow)
{
X11AppContext::mainWindow = mainWindow;
- X11AppContext::mainWindowHandle = (X11WindowHandle)mainWindow->getNativeHandle().handleValues[1];
+ X11AppContext::mainWindowHandle =
+ (X11WindowHandle)mainWindow->getNativeHandle().handleValues[1];
mainWindow->show();
while (!X11AppContext::isTerminated)
{
@@ -104,20 +113,33 @@ public:
int currentWidth = 0;
int currentHeight = 0;
bool fixedSized = false;
- X11PlatformWindow(const WindowDesc &desc)
+ X11PlatformWindow(const WindowDesc& desc)
{
currentWidth = desc.width;
currentHeight = desc.height;
- int blackColor = BlackPixel(X11AppContext::xdisplay, DefaultScreen(X11AppContext::xdisplay));
- int whiteColor = WhitePixel(X11AppContext::xdisplay, DefaultScreen(X11AppContext::xdisplay));
- handle = XCreateSimpleWindow(X11AppContext::xdisplay, DefaultRootWindow(X11AppContext::xdisplay), 0, 0,
- desc.width, desc.height, 0, blackColor, blackColor);
+ int blackColor =
+ BlackPixel(X11AppContext::xdisplay, DefaultScreen(X11AppContext::xdisplay));
+ int whiteColor =
+ WhitePixel(X11AppContext::xdisplay, DefaultScreen(X11AppContext::xdisplay));
+ handle = XCreateSimpleWindow(
+ X11AppContext::xdisplay,
+ DefaultRootWindow(X11AppContext::xdisplay),
+ 0,
+ 0,
+ desc.width,
+ desc.height,
+ 0,
+ blackColor,
+ blackColor);
X11AppContext::windows[handle] = this;
Atom wmDelete = XInternAtom(X11AppContext::xdisplay, "WM_DELETE_WINDOW", True);
XSetWMProtocols(X11AppContext::xdisplay, handle, &wmDelete, 1);
- XSelectInput(X11AppContext::xdisplay, handle, StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
- ButtonPressMask | ButtonReleaseMask | ExposureMask | FocusChangeMask);
+ XSelectInput(
+ X11AppContext::xdisplay,
+ handle,
+ StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
+ ButtonPressMask | ButtonReleaseMask | ExposureMask | FocusChangeMask);
if (desc.style == WindowStyle::FixedSize)
{
@@ -127,10 +149,7 @@ public:
setText(desc.title);
}
- ~X11PlatformWindow()
- {
- close();
- }
+ ~X11PlatformWindow() { close(); }
void setFixedSizeHint(int w, int h)
{
@@ -158,12 +177,27 @@ public:
X11WindowHandle winRoot = 0, winParent = 0;
X11WindowHandle* winChildren = nullptr;
unsigned int numChilren = 0;
- XQueryTree(X11AppContext::xdisplay, handle, &winRoot, &winParent, &winChildren, &numChilren);
+ XQueryTree(
+ X11AppContext::xdisplay,
+ handle,
+ &winRoot,
+ &winParent,
+ &winChildren,
+ &numChilren);
unsigned borderWidth, depth;
- XGetGeometry(X11AppContext::xdisplay, handle, &winRoot, &rect.x, &rect.y, (uint32_t*)&rect.width, (uint32_t*)&rect.height, &borderWidth, &depth);
+ XGetGeometry(
+ X11AppContext::xdisplay,
+ handle,
+ &winRoot,
+ &rect.x,
+ &rect.y,
+ (uint32_t*)&rect.width,
+ (uint32_t*)&rect.height,
+ &borderWidth,
+ &depth);
return rect;
}
-
+
virtual void centerScreen() override
{
auto currentRect = getClientRect();
@@ -186,7 +220,8 @@ public:
}
virtual bool getFocused() override
{
- if (!handle) return false;
+ if (!handle)
+ return false;
int revertTo;
X11WindowHandle focusedWindow;
XGetInputFocus(X11AppContext::xdisplay, &focusedWindow, &revertTo);
@@ -202,18 +237,16 @@ public:
}
virtual void setText(String text) override
{
- if (!handle) return;
+ if (!handle)
+ return;
XStoreName(X11AppContext::xdisplay, handle, text.getBuffer());
XClassHint* hint = XAllocClassHint();
- hint->res_class = (char *)"Slang platform window";
- hint->res_name = (char *)"Slang platform window";
+ hint->res_class = (char*)"Slang platform window";
+ hint->res_name = (char*)"Slang platform window";
XSetClassHint(X11AppContext::xdisplay, handle, hint);
XFree(hint);
}
- virtual bool getVisible() override
- {
- return visible;
- }
+ virtual bool getVisible() override { return visible; }
virtual void show() override
{
XMapWindow(X11AppContext::xdisplay, handle);
@@ -221,16 +254,17 @@ public:
}
virtual void hide() override
{
- if (!handle) return;
+ if (!handle)
+ return;
XUnmapWindow(X11AppContext::xdisplay, handle);
visible = false;
}
virtual int getCurrentDpi() override
{
- char *resourceString = XResourceManagerString(X11AppContext::xdisplay);
+ char* resourceString = XResourceManagerString(X11AppContext::xdisplay);
XrmDatabase db;
XrmValue value;
- char *type = NULL;
+ char* type = NULL;
double dpi = 96.0;
db = XrmGetStringDatabase(resourceString);
if (resourceString)
@@ -263,12 +297,18 @@ public:
ButtonState::Enum getButtonState(int state)
{
ButtonState::Enum buttonState = ButtonState::Enum::None;
- if (state & ShiftMask) addButtonState(buttonState, ButtonState::Enum::Shift);
- if (state & ControlMask) addButtonState(buttonState, ButtonState::Enum::Control);
- if (state & Mod1Mask) addButtonState(buttonState, ButtonState::Enum::Alt);
- if (state & Button1Mask) addButtonState(buttonState, ButtonState::Enum::LeftButton);
- if (state & Button2Mask) addButtonState(buttonState, ButtonState::Enum::MiddleButton);
- if (state & Button3Mask) addButtonState(buttonState, ButtonState::Enum::RightButton);
+ if (state & ShiftMask)
+ addButtonState(buttonState, ButtonState::Enum::Shift);
+ if (state & ControlMask)
+ addButtonState(buttonState, ButtonState::Enum::Control);
+ if (state & Mod1Mask)
+ addButtonState(buttonState, ButtonState::Enum::Alt);
+ if (state & Button1Mask)
+ addButtonState(buttonState, ButtonState::Enum::LeftButton);
+ if (state & Button2Mask)
+ addButtonState(buttonState, ButtonState::Enum::MiddleButton);
+ if (state & Button3Mask)
+ addButtonState(buttonState, ButtonState::Enum::RightButton);
return buttonState;
}
@@ -291,7 +331,14 @@ public:
}
}
- void handleMouseEvent(MouseEvent eventType, int x, int y, int delta, int button, int state, unsigned long time)
+ void handleMouseEvent(
+ MouseEvent eventType,
+ int x,
+ int y,
+ int delta,
+ int button,
+ int state,
+ unsigned long time)
{
auto buttonState = getButtonState(state);
if (button == Button1)
@@ -308,20 +355,11 @@ public:
switch (eventType)
{
- case MouseEvent::Down:
- events.mouseDown(e);
- break;
- case MouseEvent::Up:
- events.mouseUp(e);
- break;
- case MouseEvent::Move:
- events.mouseMove(e);
- break;
- case MouseEvent::Scroll:
- events.mouseWheel(e);
- break;
- default:
- break;
+ case MouseEvent::Down: events.mouseDown(e); break;
+ case MouseEvent::Up: events.mouseUp(e); break;
+ case MouseEvent::Move: events.mouseMove(e); break;
+ case MouseEvent::Scroll: events.mouseWheel(e); break;
+ default: break;
}
}
@@ -332,14 +370,9 @@ public:
Application::quit();
}
- void handleExposeEvent()
- {
- }
-
- void handleFocus(bool focus)
- {
- }
+ void handleExposeEvent() {}
+ void handleFocus(bool focus) {}
};
Window* Application::createWindow(const WindowDesc& desc)
@@ -361,7 +394,7 @@ void doEventsImpl(bool waitForEvents)
auto xdisplay = X11AppContext::xdisplay;
if (!X11AppContext::xdisplay)
return;
-
+
static bool supressInvokeTasks = false;
X11PlatformWindow* sysWindow = nullptr;
KeyCode vKeyCode = KeyCode::None;
@@ -379,7 +412,7 @@ void doEventsImpl(bool waitForEvents)
{
if (X11AppContext::keyStates[iKeyCode] == KeyState::Released)
X11AppContext::keyStates[iKeyCode] = KeyState::Pressed;
- else if (X11AppContext::keyStates[iKeyCode] == KeyState::Pressed)
+ else if (X11AppContext::keyStates[iKeyCode] == KeyState::Pressed)
X11AppContext::keyStates[iKeyCode] = KeyState::Hold;
}
if (X11AppContext::windows.tryGetValue(nextEvent.xkey.window, sysWindow))
@@ -404,8 +437,14 @@ void doEventsImpl(bool waitForEvents)
if (X11AppContext::windows.tryGetValue(nextEvent.xmotion.window, sysWindow))
{
X11AppContext::currentMouseEventWindow = sysWindow;
- sysWindow->handleMouseEvent(MouseEvent::Move, nextEvent.xmotion.x, nextEvent.xmotion.y, 0,
- 0, nextEvent.xmotion.state, nextEvent.xmotion.time);
+ sysWindow->handleMouseEvent(
+ MouseEvent::Move,
+ nextEvent.xmotion.x,
+ nextEvent.xmotion.y,
+ 0,
+ 0,
+ nextEvent.xmotion.state,
+ nextEvent.xmotion.time);
}
break;
case ButtonPress:
@@ -413,28 +452,54 @@ void doEventsImpl(bool waitForEvents)
{
X11AppContext::currentMouseEventWindow = sysWindow;
if (nextEvent.xbutton.button <= Button3)
- sysWindow->handleMouseEvent(MouseEvent::Down, nextEvent.xbutton.x, nextEvent.xbutton.y, 0,
- nextEvent.xbutton.button, nextEvent.xbutton.state, nextEvent.xbutton.time);
+ sysWindow->handleMouseEvent(
+ MouseEvent::Down,
+ nextEvent.xbutton.x,
+ nextEvent.xbutton.y,
+ 0,
+ nextEvent.xbutton.button,
+ nextEvent.xbutton.state,
+ nextEvent.xbutton.time);
else if (nextEvent.xbutton.button == Button4)
- sysWindow->handleMouseEvent(MouseEvent::Scroll, nextEvent.xbutton.x, nextEvent.xbutton.y, 120,
- nextEvent.xbutton.button, nextEvent.xbutton.state, nextEvent.xbutton.time);
+ sysWindow->handleMouseEvent(
+ MouseEvent::Scroll,
+ nextEvent.xbutton.x,
+ nextEvent.xbutton.y,
+ 120,
+ nextEvent.xbutton.button,
+ nextEvent.xbutton.state,
+ nextEvent.xbutton.time);
else if (nextEvent.xbutton.button == Button5)
- sysWindow->handleMouseEvent(MouseEvent::Scroll, nextEvent.xbutton.x, nextEvent.xbutton.y, -120,
- nextEvent.xbutton.button, nextEvent.xbutton.state, nextEvent.xbutton.time);
+ sysWindow->handleMouseEvent(
+ MouseEvent::Scroll,
+ nextEvent.xbutton.x,
+ nextEvent.xbutton.y,
+ -120,
+ nextEvent.xbutton.button,
+ nextEvent.xbutton.state,
+ nextEvent.xbutton.time);
}
break;
case ButtonRelease:
if (X11AppContext::windows.tryGetValue(nextEvent.xbutton.window, sysWindow))
{
X11AppContext::currentMouseEventWindow = sysWindow;
- sysWindow->handleMouseEvent(MouseEvent::Up, nextEvent.xbutton.x, nextEvent.xbutton.y, 0,
- nextEvent.xbutton.button, nextEvent.xbutton.state, nextEvent.xbutton.time);
+ sysWindow->handleMouseEvent(
+ MouseEvent::Up,
+ nextEvent.xbutton.x,
+ nextEvent.xbutton.y,
+ 0,
+ nextEvent.xbutton.button,
+ nextEvent.xbutton.state,
+ nextEvent.xbutton.time);
}
break;
case ConfigureNotify:
if (X11AppContext::windows.tryGetValue(nextEvent.xconfigure.window, sysWindow))
{
- sysWindow->handleResizeEvent(nextEvent.xconfigure.width, nextEvent.xconfigure.height);
+ sysWindow->handleResizeEvent(
+ nextEvent.xconfigure.width,
+ nextEvent.xconfigure.height);
}
break;
case Expose:
@@ -469,6 +534,6 @@ void doEventsImpl(bool waitForEvents)
}
}
-}
+} // namespace platform
#endif