Merge branch 'fix-linuxwindow' of https://github.com/nothingTVatYT/FlaxEngine into nothingTVatYT-fix-linuxwindow

This commit is contained in:
Wojtek Figat
2023-12-16 12:35:26 +01:00
3 changed files with 45 additions and 9 deletions

View File

@@ -94,6 +94,7 @@ X11::XcursorImage* CursorsImg[(int32)CursorType::MAX];
Dictionary<StringAnsi, X11::KeyCode> KeyNameMap;
Array<KeyboardKeys> KeyCodeMap;
Delegate<void*> LinuxPlatform::xEventRecieved;
const Window* mouseTrackingWindow;
// Message boxes configuration
#define LINUX_DIALOG_MIN_BUTTON_WIDTH 64
@@ -1917,6 +1918,8 @@ bool LinuxPlatform::Init()
if (PlatformBase::Init())
return true;
mouseTrackingWindow = nullptr;
char fileNameBuffer[1024];
// Init timing
@@ -2260,6 +2263,17 @@ bool LinuxPlatform::Init()
return false;
}
void LinuxPlatform::StartTrackingMouse(const Window* window)
{
mouseTrackingWindow = window;
}
void LinuxPlatform::EndTrackingMouse(const Window* window)
{
if (mouseTrackingWindow == window)
mouseTrackingWindow = nullptr;
}
void LinuxPlatform::BeforeRun()
{
}
@@ -2398,7 +2412,7 @@ void LinuxPlatform::Tick()
// Update input context focus
X11::XSetICFocus(IC);
window = WindowsManager::GetByNativePtr((void*)event.xfocus.window);
if (window)
if (window && mouseTrackingWindow == nullptr)
{
window->OnGotFocus();
}
@@ -2407,7 +2421,7 @@ void LinuxPlatform::Tick()
// Update input context focus
X11::XUnsetICFocus(IC);
window = WindowsManager::GetByNativePtr((void*)event.xfocus.window);
if (window)
if (window && mouseTrackingWindow == nullptr)
{
window->OnLostFocus();
}
@@ -2514,23 +2528,32 @@ void LinuxPlatform::Tick()
break;
case ButtonPress:
window = WindowsManager::GetByNativePtr((void*)event.xbutton.window);
if (window)
if (mouseTrackingWindow)
((LinuxWindow*)mouseTrackingWindow)->OnButtonPress(&event.xbutton);
else if (window)
window->OnButtonPress(&event.xbutton);
break;
case ButtonRelease:
window = WindowsManager::GetByNativePtr((void*)event.xbutton.window);
if (window)
if (mouseTrackingWindow)
((LinuxWindow*)mouseTrackingWindow)->OnButtonRelease(&event.xbutton);
else if (window)
window->OnButtonRelease(&event.xbutton);
break;
case MotionNotify:
window = WindowsManager::GetByNativePtr((void*)event.xmotion.window);
if (window)
if (mouseTrackingWindow)
((LinuxWindow*)mouseTrackingWindow)->OnMotionNotify(&event.xmotion);
else if (window)
window->OnMotionNotify(&event.xmotion);
break;
case EnterNotify:
// nothing?
break;
case LeaveNotify:
window = WindowsManager::GetByNativePtr((void*)event.xcrossing.window);
if (mouseTrackingWindow)
((LinuxWindow*)mouseTrackingWindow)->OnLeaveNotify(&event.xcrossing);
if (window)
window->OnLeaveNotify(&event.xcrossing);
break;

View File

@@ -139,6 +139,8 @@ public:
static String GetWorkingDirectory();
static bool SetWorkingDirectory(const String& path);
static Window* CreateWindow(const CreateWindowSettings& settings);
static void StartTrackingMouse(const Window* window);
static void EndTrackingMouse(const Window *window);
static void GetEnvironmentVariables(Dictionary<String, String, HeapAllocation>& result);
static bool GetEnvironmentVariable(const String& name, String& value);
static bool SetEnvironmentVariable(const String& name, const String& value);

View File

@@ -54,7 +54,7 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings)
return;
auto screen = XDefaultScreen(display);
// Cache data
// Cache data
int32 width = Math::TruncToInt(settings.Size.X);
int32 height = Math::TruncToInt(settings.Size.Y);
_clientSize = Float2((float)width, (float)height);
@@ -111,6 +111,12 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings)
windowAttributes.border_pixel = XBlackPixel(display, screen);
windowAttributes.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask | ExposureMask;
if (!settings.IsRegularWindow)
{
windowAttributes.save_under = true;
windowAttributes.override_redirect = true;
}
// TODO: implement all window settings
/*
bool Fullscreen;
@@ -118,11 +124,16 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings)
bool AllowMaximize;
*/
unsigned long valueMask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
if (!settings.IsRegularWindow)
{
valueMask |= CWOverrideRedirect | CWSaveUnder;
}
const X11::Window window = X11::XCreateWindow(
display, X11::XRootWindow(display, screen), x, y,
width, height, 0, visualInfo->depth, InputOutput,
visualInfo->visual,
CWBackPixel | CWBorderPixel | CWEventMask | CWColormap, &windowAttributes);
valueMask, &windowAttributes);
_window = window;
LinuxWindow::SetTitle(settings.Title);
@@ -811,12 +822,12 @@ void LinuxWindow::SetTitle(const StringView& title)
void LinuxWindow::StartTrackingMouse(bool useMouseScreenOffset)
{
// TODO: impl this
LinuxPlatform::StartTrackingMouse(this);
}
void LinuxWindow::EndTrackingMouse()
{
// TODO: impl this
LinuxPlatform::EndTrackingMouse(this);
}
void LinuxWindow::SetCursor(CursorType type)