Compare commits
15 Commits
aa70815f5f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b03a10d601 | |||
| a02355eb20 | |||
| 7d07c069b9 | |||
| b387457337 | |||
| 5474048db5 | |||
| 7370d562de | |||
| b85cbd5edf | |||
| 40c002323e | |||
| 0e0624ceb6 | |||
| a6a581347e | |||
| e843be0a1c | |||
| 421e0a6897 | |||
| e4bbc31c7b | |||
| a1f00aa443 | |||
| d0606a1939 |
@@ -1,20 +1,20 @@
|
|||||||
From c9dd87198ce5262e6ddf6bf3b0c18eb84784d35e Mon Sep 17 00:00:00 2001
|
From e71364497354b511159bf3d883b0e6168f430187 Mon Sep 17 00:00:00 2001
|
||||||
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
|
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
|
||||||
Date: Wed, 15 Apr 2026 17:52:54 +0300
|
Date: Tue, 7 Jul 2026 05:04:45 +0300
|
||||||
Subject: [PATCH] linux-window-server-sdl2
|
Subject: [PATCH] linux-window-server-sdl2
|
||||||
|
|
||||||
---
|
---
|
||||||
userspace/libraries/LibGUI/Widget/Widget.cpp | 2 +-
|
userspace/libraries/LibGUI/Widget/Widget.cpp | 2 +-
|
||||||
userspace/libraries/LibGUI/Window.cpp | 9 +-
|
userspace/libraries/LibGUI/Window.cpp | 11 +-
|
||||||
userspace/programs/ProgramLauncher/main.cpp | 2 +-
|
userspace/programs/ProgramLauncher/main.cpp | 2 +-
|
||||||
userspace/programs/Terminal/Terminal.cpp | 4 +-
|
userspace/programs/Terminal/Terminal.cpp | 10 +-
|
||||||
.../programs/WindowServer/CMakeLists.txt | 3 +
|
.../programs/WindowServer/CMakeLists.txt | 3 +
|
||||||
.../programs/WindowServer/Framebuffer.cpp | 52 +--
|
.../programs/WindowServer/Framebuffer.cpp | 52 +--
|
||||||
userspace/programs/WindowServer/Window.cpp | 29 +-
|
userspace/programs/WindowServer/Window.cpp | 29 +-
|
||||||
.../programs/WindowServer/WindowServer.cpp | 47 ++-
|
.../programs/WindowServer/WindowServer.cpp | 47 ++-
|
||||||
.../programs/WindowServer/WindowServer.h | 1 +
|
.../programs/WindowServer/WindowServer.h | 1 +
|
||||||
userspace/programs/WindowServer/main.cpp | 357 ++++++++++++------
|
userspace/programs/WindowServer/main.cpp | 357 ++++++++++++------
|
||||||
10 files changed, 340 insertions(+), 166 deletions(-)
|
10 files changed, 345 insertions(+), 169 deletions(-)
|
||||||
|
|
||||||
diff --git a/userspace/libraries/LibGUI/Widget/Widget.cpp b/userspace/libraries/LibGUI/Widget/Widget.cpp
|
diff --git a/userspace/libraries/LibGUI/Widget/Widget.cpp b/userspace/libraries/LibGUI/Widget/Widget.cpp
|
||||||
index d6489d87..c532fb04 100644
|
index d6489d87..c532fb04 100644
|
||||||
@@ -30,7 +30,7 @@ index d6489d87..c532fb04 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp
|
diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp
|
||||||
index b4172f70..3a0e9cca 100644
|
index 607421eb..d8aeee7e 100644
|
||||||
--- a/userspace/libraries/LibGUI/Window.cpp
|
--- a/userspace/libraries/LibGUI/Window.cpp
|
||||||
+++ b/userspace/libraries/LibGUI/Window.cpp
|
+++ b/userspace/libraries/LibGUI/Window.cpp
|
||||||
@@ -4,9 +4,8 @@
|
@@ -4,9 +4,8 @@
|
||||||
@@ -44,7 +44,7 @@ index b4172f70..3a0e9cca 100644
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -271,7 +270,7 @@ namespace LibGUI
|
@@ -311,23 +310,23 @@ namespace LibGUI
|
||||||
|
|
||||||
void Window::cleanup()
|
void Window::cleanup()
|
||||||
{
|
{
|
||||||
@@ -53,24 +53,25 @@ index b4172f70..3a0e9cca 100644
|
|||||||
close(m_server_fd);
|
close(m_server_fd);
|
||||||
close(m_epoll_fd);
|
close(m_epoll_fd);
|
||||||
}
|
}
|
||||||
@@ -279,7 +278,7 @@ namespace LibGUI
|
|
||||||
BAN::ErrorOr<void> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
|
BAN::ErrorOr<bool> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
|
||||||
{
|
{
|
||||||
|
- void* framebuffer_addr = smo_map(event.smo_key);
|
||||||
|
+ void* framebuffer_addr = shmat(event.smo_key, nullptr, 0);
|
||||||
|
if (framebuffer_addr == nullptr)
|
||||||
|
{
|
||||||
|
- if (errno == ENOENT)
|
||||||
|
+ if (errno == EINVAL)
|
||||||
|
return false;
|
||||||
|
return BAN::Error::from_errno(errno);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_framebuffer_smo)
|
if (m_framebuffer_smo)
|
||||||
- munmap(m_framebuffer_smo, m_width * m_height * 4);
|
- munmap(m_framebuffer_smo, m_width * m_height * 4);
|
||||||
+ shmdt(m_framebuffer_smo);
|
+ shmdt(m_framebuffer_smo);
|
||||||
m_framebuffer_smo = nullptr;
|
m_framebuffer_smo = nullptr;
|
||||||
|
|
||||||
TRY(m_texture.resize(event.width, event.height));
|
TRY(m_texture.resize(event.width, event.height));
|
||||||
@@ -287,7 +286,7 @@ namespace LibGUI
|
|
||||||
if (m_root_widget)
|
|
||||||
TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height }));
|
|
||||||
|
|
||||||
- void* framebuffer_addr = smo_map(event.smo_key);
|
|
||||||
+ void* framebuffer_addr = shmat(event.smo_key, nullptr, 0);
|
|
||||||
if (framebuffer_addr == nullptr)
|
|
||||||
return BAN::Error::from_errno(errno);
|
|
||||||
|
|
||||||
diff --git a/userspace/programs/ProgramLauncher/main.cpp b/userspace/programs/ProgramLauncher/main.cpp
|
diff --git a/userspace/programs/ProgramLauncher/main.cpp b/userspace/programs/ProgramLauncher/main.cpp
|
||||||
index c833c582..0e1cc460 100644
|
index c833c582..0e1cc460 100644
|
||||||
--- a/userspace/programs/ProgramLauncher/main.cpp
|
--- a/userspace/programs/ProgramLauncher/main.cpp
|
||||||
@@ -85,10 +86,18 @@ index c833c582..0e1cc460 100644
|
|||||||
const auto full_program_list = get_program_list();
|
const auto full_program_list = get_program_list();
|
||||||
|
|
||||||
diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp
|
diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp
|
||||||
index e1bd317d..8a6b5bd0 100644
|
index c470438d..709db432 100644
|
||||||
--- a/userspace/programs/Terminal/Terminal.cpp
|
--- a/userspace/programs/Terminal/Terminal.cpp
|
||||||
+++ b/userspace/programs/Terminal/Terminal.cpp
|
+++ b/userspace/programs/Terminal/Terminal.cpp
|
||||||
@@ -92,7 +92,7 @@ void Terminal::start_shell()
|
@@ -9,6 +9,7 @@
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
+#include <sys/ioctl.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <time.h>
|
||||||
|
@@ -92,7 +93,7 @@ void Terminal::start_shell()
|
||||||
close(pts_slave);
|
close(pts_slave);
|
||||||
close(pts_master);
|
close(pts_master);
|
||||||
|
|
||||||
@@ -97,7 +106,7 @@ index e1bd317d..8a6b5bd0 100644
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ void Terminal::run()
|
@@ -127,7 +128,7 @@ void Terminal::run()
|
||||||
m_window->texture().set_bg_color(m_bg_color);
|
m_window->texture().set_bg_color(m_bg_color);
|
||||||
m_window->invalidate();
|
m_window->invalidate();
|
||||||
|
|
||||||
@@ -106,6 +115,25 @@ index e1bd317d..8a6b5bd0 100644
|
|||||||
|
|
||||||
m_window->set_min_size(m_font.width() * 8, m_font.height() * 2);
|
m_window->set_min_size(m_font.width() * 8, m_font.height() * 2);
|
||||||
|
|
||||||
|
@@ -147,7 +148,8 @@ void Terminal::run()
|
||||||
|
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
|
||||||
|
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
|
||||||
|
};
|
||||||
|
- if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
|
||||||
|
+
|
||||||
|
+ if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
|
||||||
|
perror("tcsetwinsize");
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -212,7 +214,7 @@ void Terminal::run()
|
||||||
|
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
|
||||||
|
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
|
||||||
|
};
|
||||||
|
- if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
|
||||||
|
+ if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
|
||||||
|
perror("tcsetwinsize");
|
||||||
|
});
|
||||||
|
|
||||||
diff --git a/userspace/programs/WindowServer/CMakeLists.txt b/userspace/programs/WindowServer/CMakeLists.txt
|
diff --git a/userspace/programs/WindowServer/CMakeLists.txt b/userspace/programs/WindowServer/CMakeLists.txt
|
||||||
index 8fdf79f9..fcaf441d 100644
|
index 8fdf79f9..fcaf441d 100644
|
||||||
--- a/userspace/programs/WindowServer/CMakeLists.txt
|
--- a/userspace/programs/WindowServer/CMakeLists.txt
|
||||||
@@ -199,7 +227,7 @@ index 0e727e8f..119f1451 100644
|
|||||||
return framebuffer;
|
return framebuffer;
|
||||||
}
|
}
|
||||||
diff --git a/userspace/programs/WindowServer/Window.cpp b/userspace/programs/WindowServer/Window.cpp
|
diff --git a/userspace/programs/WindowServer/Window.cpp b/userspace/programs/WindowServer/Window.cpp
|
||||||
index 1e66f522..9759eec9 100644
|
index 78de89c9..c5405695 100644
|
||||||
--- a/userspace/programs/WindowServer/Window.cpp
|
--- a/userspace/programs/WindowServer/Window.cpp
|
||||||
+++ b/userspace/programs/WindowServer/Window.cpp
|
+++ b/userspace/programs/WindowServer/Window.cpp
|
||||||
@@ -5,15 +5,14 @@
|
@@ -5,15 +5,14 @@
|
||||||
@@ -221,7 +249,7 @@ index 1e66f522..9759eec9 100644
|
|||||||
|
|
||||||
LibGUI::EventPacket::DestroyWindowEvent packet;
|
LibGUI::EventPacket::DestroyWindowEvent packet;
|
||||||
|
|
||||||
@@ -47,16 +46,16 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
|
@@ -45,16 +44,16 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
const size_t fb_bytes = width * height * 4;
|
const size_t fb_bytes = width * height * 4;
|
||||||
|
|
||||||
@@ -244,7 +272,7 @@ index 1e66f522..9759eec9 100644
|
|||||||
|
|
||||||
{
|
{
|
||||||
const auto old_area = m_client_area;
|
const auto old_area = m_client_area;
|
||||||
@@ -70,16 +69,14 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
|
@@ -68,16 +67,14 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
|
||||||
return title_bar_ret.release_error();
|
return title_bar_ret.release_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +294,7 @@ index 1e66f522..9759eec9 100644
|
|||||||
m_client_area.max_x = m_client_area.min_x + width;
|
m_client_area.max_x = m_client_area.min_x + width;
|
||||||
m_client_area.max_y = m_client_area.min_y + height;
|
m_client_area.max_y = m_client_area.min_y + height;
|
||||||
diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp
|
diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp
|
||||||
index 2c67d6c0..600704fd 100644
|
index e6b01476..a14074c3 100644
|
||||||
--- a/userspace/programs/WindowServer/WindowServer.cpp
|
--- a/userspace/programs/WindowServer/WindowServer.cpp
|
||||||
+++ b/userspace/programs/WindowServer/WindowServer.cpp
|
+++ b/userspace/programs/WindowServer/WindowServer.cpp
|
||||||
@@ -8,19 +8,20 @@
|
@@ -8,19 +8,20 @@
|
||||||
@@ -295,16 +323,16 @@ index 2c67d6c0..600704fd 100644
|
|||||||
{
|
{
|
||||||
MUST(m_background_image.resize(m_framebuffer.width * m_framebuffer.height, 0xFF101010));
|
MUST(m_background_image.resize(m_framebuffer.width * m_framebuffer.height, 0xFF101010));
|
||||||
|
|
||||||
@@ -440,7 +441,7 @@ static void update_volume(const char* new_volume)
|
@@ -512,7 +513,7 @@ static void update_volume(const char* new_volume)
|
||||||
|
|
||||||
void WindowServer::on_key_event(LibInput::KeyEvent event)
|
void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||||
{
|
{
|
||||||
- if (event.key == LibInput::Key::Super)
|
- if (event.key == LibInput::Key::LeftSuper)
|
||||||
+ if (event.key == LibInput::Key::RightCtrl)
|
+ if (event.key == LibInput::Key::RightCtrl)
|
||||||
m_is_mod_key_held = event.pressed();
|
m_is_mod_key_held = event.pressed();
|
||||||
|
|
||||||
if (event.pressed() && event.key == LibInput::Key::VolumeDown)
|
if (event.pressed() && event.key == LibInput::Key::VolumeDown)
|
||||||
@@ -461,7 +462,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
@@ -533,7 +534,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
@@ -313,7 +341,7 @@ index 2c67d6c0..600704fd 100644
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
@@ -475,7 +476,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
@@ -547,7 +548,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
@@ -322,7 +350,7 @@ index 2c67d6c0..600704fd 100644
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
@@ -1599,16 +1600,34 @@ void WindowServer::sync()
|
@@ -1664,16 +1665,34 @@ void WindowServer::sync()
|
||||||
|
|
||||||
for (size_t i = 0; i < m_damaged_area_count; i++)
|
for (size_t i = 0; i < m_damaged_area_count; i++)
|
||||||
{
|
{
|
||||||
@@ -364,10 +392,10 @@ index 2c67d6c0..600704fd 100644
|
|||||||
|
|
||||||
Rectangle WindowServer::cursor_area() const
|
Rectangle WindowServer::cursor_area() const
|
||||||
diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h
|
diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h
|
||||||
index 94fbc774..bcd7a6b9 100644
|
index 9e2dc70e..40813f2e 100644
|
||||||
--- a/userspace/programs/WindowServer/WindowServer.h
|
--- a/userspace/programs/WindowServer/WindowServer.h
|
||||||
+++ b/userspace/programs/WindowServer/WindowServer.h
|
+++ b/userspace/programs/WindowServer/WindowServer.h
|
||||||
@@ -62,6 +62,7 @@ public:
|
@@ -65,6 +65,7 @@ public:
|
||||||
|
|
||||||
bool is_damaged() const { return m_damaged_area_count > 0 || m_is_bouncing_window; }
|
bool is_damaged() const { return m_damaged_area_count > 0 || m_is_bouncing_window; }
|
||||||
bool is_stopped() const { return m_is_stopped; }
|
bool is_stopped() const { return m_is_stopped; }
|
||||||
@@ -376,7 +404,7 @@ index 94fbc774..bcd7a6b9 100644
|
|||||||
private:
|
private:
|
||||||
void on_mouse_move_impl(int32_t new_x, int32_t new_y);
|
void on_mouse_move_impl(int32_t new_x, int32_t new_y);
|
||||||
diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp
|
diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp
|
||||||
index 46f2ba6d..520c8e7d 100644
|
index 61d10e97..e77e5d97 100644
|
||||||
--- a/userspace/programs/WindowServer/main.cpp
|
--- a/userspace/programs/WindowServer/main.cpp
|
||||||
+++ b/userspace/programs/WindowServer/main.cpp
|
+++ b/userspace/programs/WindowServer/main.cpp
|
||||||
@@ -10,7 +10,6 @@
|
@@ -10,7 +10,6 @@
|
||||||
@@ -518,7 +546,7 @@ index 46f2ba6d..520c8e7d 100644
|
|||||||
if (epoll_events == -1 && errno != EINTR)
|
if (epoll_events == -1 && errno != EINTR)
|
||||||
{
|
{
|
||||||
dwarnln("epoll_pwait2: {}", strerror(errno));
|
dwarnln("epoll_pwait2: {}", strerror(errno));
|
||||||
@@ -333,48 +288,6 @@ int main()
|
@@ -334,48 +289,6 @@ int main()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +595,7 @@ index 46f2ba6d..520c8e7d 100644
|
|||||||
const int client_fd = events[i].data.fd;
|
const int client_fd = events[i].data.fd;
|
||||||
if (events[i].events & (EPOLLHUP | EPOLLERR))
|
if (events[i].events & (EPOLLHUP | EPOLLERR))
|
||||||
{
|
{
|
||||||
@@ -500,3 +413,237 @@ int main()
|
@@ -507,3 +420,237 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,5 +834,5 @@ index 46f2ba6d..520c8e7d 100644
|
|||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
--
|
--
|
||||||
2.53.0
|
2.54.0
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,14 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
add_compile_definitions(-Dstddbg=stdout)
|
add_compile_definitions(-Dstddbg=stdout)
|
||||||
add_compile_options(-g)
|
add_compile_options(-g)
|
||||||
|
|
||||||
if(BANAN_OS)
|
set(PLATFORM "banan-os" CACHE STRING "target platform")
|
||||||
|
|
||||||
|
set(VALID_PLATFORMS "banan-os" "SDL3")
|
||||||
|
if(NOT PLATFORM IN_LIST VALID_PLATFORMS)
|
||||||
|
message(FATAL_ERROR "platform \"${PLATFORM}\" not known, valid platforms are ${VALID_PLATFORMS}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "banan-os")
|
||||||
find_library(BAN ban REQUIRED)
|
find_library(BAN ban REQUIRED)
|
||||||
add_library(ban SHARED IMPORTED)
|
add_library(ban SHARED IMPORTED)
|
||||||
set_target_properties(ban PROPERTIES IMPORTED_LOCATION "${BAN}")
|
set_target_properties(ban PROPERTIES IMPORTED_LOCATION "${BAN}")
|
||||||
@@ -48,16 +55,19 @@ else()
|
|||||||
set_target_properties(libc PROPERTIES IMPORTED_LOCATION "${LIBC}")
|
set_target_properties(libc PROPERTIES IMPORTED_LOCATION "${LIBC}")
|
||||||
|
|
||||||
add_subdirectory(banan-os/BAN)
|
add_subdirectory(banan-os/BAN)
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibClipboard)
|
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibDEFLATE)
|
add_subdirectory(banan-os/userspace/libraries/LibDEFLATE)
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibFont)
|
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibGUI)
|
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibImage)
|
|
||||||
add_subdirectory(banan-os/userspace/libraries/LibInput)
|
|
||||||
|
|
||||||
add_subdirectory(banan-os/userspace/programs/ProgramLauncher)
|
if(PLATFORM STREQUAL "banan-os")
|
||||||
add_subdirectory(banan-os/userspace/programs/Terminal)
|
add_subdirectory(banan-os/userspace/libraries/LibClipboard)
|
||||||
add_subdirectory(banan-os/userspace/programs/WindowServer)
|
add_subdirectory(banan-os/userspace/libraries/LibFont)
|
||||||
|
add_subdirectory(banan-os/userspace/libraries/LibGUI)
|
||||||
|
add_subdirectory(banan-os/userspace/libraries/LibImage)
|
||||||
|
add_subdirectory(banan-os/userspace/libraries/LibInput)
|
||||||
|
|
||||||
|
add_subdirectory(banan-os/userspace/programs/ProgramLauncher)
|
||||||
|
add_subdirectory(banan-os/userspace/programs/Terminal)
|
||||||
|
add_subdirectory(banan-os/userspace/programs/WindowServer)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(xbanan)
|
add_subdirectory(xbanan)
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -1,29 +1,45 @@
|
|||||||
# xbanan
|
# xbanan
|
||||||
|
|
||||||
An X11 compatibility layer for [banan-os's](https://git.bananymous.com/Bananymous/banan-os) native GUI windowing system.
|
A portable X11 compatibility layer. There are 2 officially supported platforms: [banan-os's](https://git.bananymous.com/Bananymous/banan-os) native GUI windowing system and SDL3.
|
||||||
|
|
||||||
## Running on linux
|
## Running on linux
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
You need to have SDL3 development library and X11 headers installed on your system.
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
```sh
|
```sh
|
||||||
git clone --recursive https://git.bananymous.com/Bananymous/xbanan.git
|
git clone --recursive https://git.bananymous.com/Bananymous/xbanan.git
|
||||||
cd xbanan
|
cd xbanan
|
||||||
|
|
||||||
cd banan-os
|
cmake -B build -S . -DPLATFORM=SDL3
|
||||||
git apply ../0001-linux-window-server-sdl2.patch
|
cmake --build build --parallel $(nproc)
|
||||||
cd ..
|
|
||||||
|
|
||||||
cmake -B build -S . -G Ninja
|
|
||||||
cmake --build build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running
|
### Running
|
||||||
|
|
||||||
To start the WindowServer, run the following command in project root
|
To start xbanan, run the following command in project root
|
||||||
```sh
|
```sh
|
||||||
./build/banan-os/userspace/programs/WindowServer/WindowServer
|
./build/xbanan/xbanan
|
||||||
```
|
```
|
||||||
To run X11 apps specify `DISPLAY=:69` environment variable. For example
|
To run X11 apps, specify `DISPLAY=:69` environment variable. For example
|
||||||
```sh
|
```sh
|
||||||
DISPLAY=:69 xeyes
|
DISPLAY=:69 xeyes
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Porting to a new platform
|
||||||
|
|
||||||
|
Add your platform to the `VALID_PLATFORMS` list in the root `CMakeLists.txt` file. Create a directory for your platform in `xbanan/<your platform>` and define the needed source files and libraries in `xbanan/CMakeLists.txt` based on your platform.
|
||||||
|
|
||||||
|
### Barebones
|
||||||
|
|
||||||
|
For the simplest port, you need to implement 3 functions: `initialize`, `create_window` and `invalidate`. Define the variable `g_platform_ops` declared in `xbanan/Platform.h` with function pointers to the your functions. You can look at the existing platforms and the `xbanan/Platform.h` header for help.
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
To handle events, you have to hook an event receiver fd for your platform using `register_event_fd` declared in `xbanan/Events.h` and define the `poll_events` function in `g_platform_ops`. When the registered fd becomes readable, xbanan will call your platform's `poll_events` function. This function should drain all of the pending events and call appropriate `on_*_event` function declared in the events header. If your platform does not expose fd(s) that can be polled for events, you can do what the SDL3 port does and create an eventfd/pipe that gets signaled periodically.
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
To install xbanan to sysroot, just copy the `build/xbanan/xbanan` to the destination. xbanan is statically linked against the libraries from this repository so you don't have to care about those. **DO NOT** use the cmake's install target, as that installs banan-os libraries to the root of the sysroot. You also need to have the x11 misc fonts at `FONT_PATH/misc` in your sysroot if you want server side font support. The fonts are shipped (public domain) with xbanan, so you can just copy `fonts/misc` into `FONT_PATH`. You can specify the `FONT_PATH` with cmake using `-DFONT_PATH=...` when configuring.
|
||||||
|
|||||||
2
banan-os
2
banan-os
Submodule banan-os updated: 1bf5e6a051...e713644973
571
xbanan/Base.cpp
571
xbanan/Base.cpp
@@ -8,8 +8,6 @@
|
|||||||
#include "SafeGetters.h"
|
#include "SafeGetters.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <LibInput/KeyEvent.h>
|
|
||||||
|
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
@@ -161,6 +159,16 @@ static const char* s_opcode_to_name[] {
|
|||||||
[X_NoOperation] = "X_NoOperation",
|
[X_NoOperation] = "X_NoOperation",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void register_display(int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||||
|
{
|
||||||
|
MUST(g_displays.push_back({
|
||||||
|
.x = x,
|
||||||
|
.y = y,
|
||||||
|
.w = width,
|
||||||
|
.h = height,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t Object::Window::full_event_mask() const
|
uint32_t Object::Window::full_event_mask() const
|
||||||
{
|
{
|
||||||
uint32_t full_event_mask = 0;
|
uint32_t full_event_mask = 0;
|
||||||
@@ -202,18 +210,18 @@ BAN::ErrorOr<void> setup_client_conneciton(Client& client_info, const xConnClien
|
|||||||
xConnSetupPrefix setup_prefix {
|
xConnSetupPrefix setup_prefix {
|
||||||
.success = 1,
|
.success = 1,
|
||||||
.lengthReason = 0, // wtf is this
|
.lengthReason = 0, // wtf is this
|
||||||
.majorVersion = client_prefix.majorVersion,
|
.majorVersion = 11,
|
||||||
.minorVersion = client_prefix.minorVersion,
|
.minorVersion = 0,
|
||||||
.length = 8 + 2*format_count + (8 + 0 + sz_xWindowRoot + sz_xDepth + sz_xVisualType) / 4,
|
.length = 8 + 2 * format_count + (8 + 0 + sz_xWindowRoot + sz_xDepth + sz_xVisualType) / 4,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, setup_prefix));
|
TRY(encode(client_info.output_buffer, setup_prefix));
|
||||||
|
|
||||||
ASSERT((client_info.fd >> 24) == 0);
|
ASSERT((client_info.fd >> 20) == 0);
|
||||||
|
|
||||||
xConnSetup setup {
|
xConnSetup setup {
|
||||||
.release = 0,
|
.release = 0,
|
||||||
.ridBase = static_cast<CARD32>(client_info.fd << 24),
|
.ridBase = static_cast<CARD32>(client_info.fd << 20),
|
||||||
.ridMask = 0x00FFFFFF,
|
.ridMask = 0x000FFFFF,
|
||||||
.motionBufferSize = 0,
|
.motionBufferSize = 0,
|
||||||
.nbytesVendor = 8,
|
.nbytesVendor = 8,
|
||||||
.maxRequestSize = 0xFFFF,
|
.maxRequestSize = 0xFFFF,
|
||||||
@@ -288,85 +296,61 @@ static BAN::ErrorOr<void> send_visibility_events_recursively(Client& client_info
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void invalidate_window_recursive(WINDOW wid, int32_t x, int32_t y, int32_t w, int32_t h)
|
static void invalidate_window_recursive(Object::Window& dst_window, int32_t dst_x, int32_t dst_y, const Object::Window& src_window, int32_t src_x, int32_t src_y, int32_t w, int32_t h)
|
||||||
{
|
{
|
||||||
ASSERT(wid != g_root.windowId);
|
ASSERT(src_window.mapped);
|
||||||
|
|
||||||
if (x + w <= 0 || y + h <= 0)
|
if (src_window.c_class == InputOutput)
|
||||||
return;
|
|
||||||
if (w <= 0 || h <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto& object = *g_objects[wid];
|
|
||||||
ASSERT(object.type == Object::Type::Window);
|
|
||||||
|
|
||||||
auto& window = object.object.get<Object::Window>();
|
|
||||||
if (!window.mapped)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto child_wid : window.children)
|
|
||||||
{
|
{
|
||||||
const auto& child_object = *g_objects[child_wid];
|
ASSERT(src_x >= 0);
|
||||||
ASSERT(child_object.type == Object::Type::Window);
|
ASSERT(src_y >= 0);
|
||||||
|
ASSERT(src_x + w <= src_window.width);
|
||||||
|
ASSERT(src_y + h <= src_window.height);
|
||||||
|
ASSERT(dst_x + w <= dst_window.width);
|
||||||
|
ASSERT(dst_y + h <= dst_window.height);
|
||||||
|
|
||||||
const auto& child_window = child_object.object.get<Object::Window>();
|
for (int32_t y = 0; y < h; y++)
|
||||||
if (!child_window.mapped)
|
{
|
||||||
continue;
|
uint32_t* dst_u32 = &dst_window.double_buffer[(dst_y + y) * dst_window.width + dst_x];
|
||||||
|
const uint32_t* src_u32 = &src_window. pixels[(src_y + y) * src_window.width + src_x];
|
||||||
const auto child_x = x - child_window.x;
|
for (int32_t x = 0; x < w; x++)
|
||||||
const auto child_y = y - child_window.y;
|
{
|
||||||
|
if (src_u32[x] != COLOR_INVISIBLE)
|
||||||
const auto child_w = BAN::Math::min<int32_t>(w - child_window.x, child_window.width - child_x);
|
dst_u32[x] = 0xFF000000 | src_u32[x];
|
||||||
const auto child_h = BAN::Math::min<int32_t>(h - child_window.y, child_window.height - child_y);
|
else if (&dst_window == &src_window)
|
||||||
|
dst_u32[x] = 0x00000000;
|
||||||
invalidate_window_recursive(
|
}
|
||||||
child_wid,
|
}
|
||||||
child_x, child_y,
|
|
||||||
child_w, child_h
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.platform_window || window.c_class == InputOnly)
|
for (auto child_wid : src_window.children)
|
||||||
return;
|
|
||||||
|
|
||||||
auto& parent_object = *g_objects[window.parent];
|
|
||||||
ASSERT(parent_object.type == Object::Type::Window);
|
|
||||||
|
|
||||||
auto& parent_window = parent_object.object.get<Object::Window>();
|
|
||||||
|
|
||||||
const uint32_t* child_pix = window.pixels.data();
|
|
||||||
const int32_t child_w = window.width;
|
|
||||||
const int32_t child_h = window.height;
|
|
||||||
|
|
||||||
uint32_t* parent_pix = parent_window.pixels.data();
|
|
||||||
const int32_t parent_w = parent_window.width;
|
|
||||||
const int32_t parent_h = parent_window.height;
|
|
||||||
|
|
||||||
// FIXME: optimize this
|
|
||||||
for (int32_t y_off = 0; y_off < h; y_off++)
|
|
||||||
{
|
{
|
||||||
const int32_t child_y = y + y_off;
|
const auto& child = g_objects[child_wid]->object.get<Object::Window>();
|
||||||
if (child_y < 0 || child_y >= child_h)
|
if (!child.mapped)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const int32_t parent_y = window.y + y + y_off;
|
const auto diff_x = src_x - child.x;
|
||||||
if (parent_y < 0 || parent_y >= parent_h)
|
const auto diff_y = src_y - child.y;
|
||||||
|
|
||||||
|
const auto min_x = BAN::Math::max<int32_t>(diff_x, 0);
|
||||||
|
const auto min_y = BAN::Math::max<int32_t>(diff_y, 0);
|
||||||
|
|
||||||
|
const auto max_x = BAN::Math::min<int32_t>(diff_x + w, child.width);
|
||||||
|
const auto max_y = BAN::Math::min<int32_t>(diff_y + h, child.height);
|
||||||
|
|
||||||
|
if (max_x <= min_x || max_y <= min_y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int32_t x_off = 0; x_off < w; x_off++)
|
invalidate_window_recursive(
|
||||||
{
|
dst_window,
|
||||||
const int32_t child_x = x + x_off;
|
dst_x - (diff_x - min_x),
|
||||||
if (child_x < 0 || child_x >= child_w)
|
dst_y - (diff_y - min_y),
|
||||||
continue;
|
child,
|
||||||
|
min_x,
|
||||||
const int32_t parent_x = window.x + x + x_off;
|
min_y,
|
||||||
if (parent_x < 0 || parent_x >= parent_w)
|
max_x - min_x,
|
||||||
continue;
|
max_y - min_y
|
||||||
|
);
|
||||||
const uint32_t color = child_pix[child_y * child_w + child_x];
|
|
||||||
if (color != COLOR_INVISIBLE)
|
|
||||||
parent_pix[parent_y * parent_w + parent_x] = color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,68 +358,120 @@ void invalidate_window(WINDOW wid, int32_t x, int32_t y, int32_t w, int32_t h)
|
|||||||
{
|
{
|
||||||
ASSERT(wid != g_root.windowId);
|
ASSERT(wid != g_root.windowId);
|
||||||
|
|
||||||
|
int32_t min_x { x }, max_x { x + w };
|
||||||
|
int32_t min_y { y }, max_y { y + h };
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (wid == g_root.windowId)
|
if (wid == g_root.windowId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& object = *g_objects[wid];
|
const auto& window = g_objects[wid]->object.get<Object::Window>();
|
||||||
ASSERT(object.type == Object::Type::Window);
|
|
||||||
|
|
||||||
auto& window = object.object.get<Object::Window>();
|
|
||||||
if (!window.mapped)
|
if (!window.mapped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (min_x < 0)
|
||||||
|
min_x = 0;
|
||||||
|
if (min_y < 0)
|
||||||
|
min_y = 0;
|
||||||
|
|
||||||
|
if (max_x > window.width)
|
||||||
|
max_x = window.width;
|
||||||
|
if (max_y > window.height)
|
||||||
|
max_y = window.height;
|
||||||
|
|
||||||
|
if (max_x <= min_x || max_y <= min_y)
|
||||||
|
return;
|
||||||
|
|
||||||
if (window.platform_window)
|
if (window.platform_window)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
x += window.x;
|
min_x += window.x;
|
||||||
y += window.y;
|
min_y += window.y;
|
||||||
wid = window.parent;
|
wid = window.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& object = *g_objects[wid];
|
auto& window = g_objects[wid]->object.get<Object::Window>();
|
||||||
ASSERT(object.type == Object::Type::Window);
|
|
||||||
|
|
||||||
auto& window = object.object.get<Object::Window>();
|
invalidate_window_recursive(
|
||||||
ASSERT(window.platform_window);
|
window, min_x, min_y,
|
||||||
|
window, min_x, min_y,
|
||||||
|
max_x - min_x,
|
||||||
|
max_y - min_y
|
||||||
|
);
|
||||||
|
|
||||||
invalidate_window_recursive(wid, x, y, w, h);
|
if (!window.platform_window_invalidated && g_platform_ops.begin_frame)
|
||||||
|
g_platform_ops.begin_frame(window.platform_window.ptr());
|
||||||
|
window.platform_window_invalidated = true;
|
||||||
|
|
||||||
const auto min_x = BAN::Math::max<int32_t>(x, 0);
|
g_platform_ops.invalidate(
|
||||||
const auto min_y = BAN::Math::max<int32_t>(y, 0);
|
window.platform_window.ptr(),
|
||||||
const auto max_x = BAN::Math::min<int32_t>(x + w, window.width);
|
&window.double_buffer[min_y * window.width + min_x],
|
||||||
const auto max_y = BAN::Math::min<int32_t>(y + h, window.height);
|
window.width * sizeof(uint32_t),
|
||||||
|
min_x, min_y,
|
||||||
if (min_x >= max_x || min_y >= max_y)
|
max_x - min_x,
|
||||||
return;
|
max_y - min_y
|
||||||
|
);
|
||||||
uint32_t* pixels = window.pixels.data();
|
|
||||||
for (auto y = min_y; y < max_y; y++)
|
|
||||||
{
|
|
||||||
for (auto x = min_x; x < max_x; x++)
|
|
||||||
{
|
|
||||||
auto& pixel = pixels[y * window.width + x];
|
|
||||||
if (pixel == COLOR_INVISIBLE)
|
|
||||||
pixel = 0x00000000;
|
|
||||||
else
|
|
||||||
pixel |= 0xFF000000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_platform_ops.invalidate(window.platform_window.ptr(), window.pixels.data(), min_x, min_y, max_x - min_x, max_y - min_y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_exposure_recursive(WINDOW wid)
|
BAN::ErrorOr<void> send_configure_notify(WINDOW wid)
|
||||||
{
|
{
|
||||||
auto& object = *g_objects[wid];
|
auto& window = g_objects[wid]->object.get<Object::Window>();
|
||||||
ASSERT(object.type == Object::Type::Window);
|
|
||||||
|
|
||||||
auto& window = object.object.get<Object::Window>();
|
{
|
||||||
|
xEvent event = { .u = {
|
||||||
|
.configureNotify = {
|
||||||
|
.event = wid,
|
||||||
|
.window = wid,
|
||||||
|
.aboveSibling = xFalse,
|
||||||
|
.x = static_cast<INT16>(window.x),
|
||||||
|
.y = static_cast<INT16>(window.y),
|
||||||
|
.width = static_cast<CARD16>(window.width),
|
||||||
|
.height = static_cast<CARD16>(window.height),
|
||||||
|
.borderWidth = 0,
|
||||||
|
.override = xFalse,
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
event.u.u.type = ConfigureNotify;
|
||||||
|
TRY(window.send_event(event, StructureNotifyMask));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& parent_object = *g_objects[window.parent];
|
||||||
|
ASSERT(parent_object.type == Object::Type::Window);
|
||||||
|
auto& parent_window = parent_object.object.get<Object::Window>();
|
||||||
|
|
||||||
|
{
|
||||||
|
xEvent event = { .u = {
|
||||||
|
.configureNotify = {
|
||||||
|
.event = window.parent,
|
||||||
|
.window = wid,
|
||||||
|
.aboveSibling = xFalse,
|
||||||
|
.x = static_cast<INT16>(window.x),
|
||||||
|
.y = static_cast<INT16>(window.y),
|
||||||
|
.width = static_cast<CARD16>(window.width),
|
||||||
|
.height = static_cast<CARD16>(window.height),
|
||||||
|
.borderWidth = 0,
|
||||||
|
.override = xFalse,
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
event.u.u.type = ConfigureNotify;
|
||||||
|
TRY(parent_window.send_event(event, SubstructureNotifyMask));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<void> send_exposure_events_recursive(WINDOW wid)
|
||||||
|
{
|
||||||
|
auto& window = g_objects[wid]->object.get<Object::Window>();
|
||||||
if (!window.mapped)
|
if (!window.mapped)
|
||||||
return;
|
return {};
|
||||||
|
|
||||||
for (auto child_wid : window.children)
|
for (auto child_wid : window.children)
|
||||||
send_exposure_recursive(child_wid);
|
TRY(send_exposure_events_recursive(child_wid));
|
||||||
|
|
||||||
|
if (window.c_class == InputOnly)
|
||||||
|
return {};
|
||||||
|
|
||||||
xEvent event = { .u = {
|
xEvent event = { .u = {
|
||||||
.expose = {
|
.expose = {
|
||||||
@@ -447,66 +483,32 @@ void send_exposure_recursive(WINDOW wid)
|
|||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
event.u.u.type = Expose;
|
event.u.u.type = Expose;
|
||||||
MUST(window.send_event(event, ExposureMask));
|
TRY(window.send_event(event, ExposureMask));
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PlatformWindowInfo
|
static WindowType get_plaform_window_info(const Object::Window& window)
|
||||||
{
|
|
||||||
PlatformWindow* parent;
|
|
||||||
WindowType type;
|
|
||||||
};
|
|
||||||
|
|
||||||
static PlatformWindowInfo get_plaform_window_info(const Object::Window& window)
|
|
||||||
{
|
{
|
||||||
static const CARD32 ATOM = g_atoms_name_to_id["ATOM"_sv];
|
static const CARD32 ATOM = g_atoms_name_to_id["ATOM"_sv];
|
||||||
static const CARD32 WINDOW = g_atoms_name_to_id["WINDOW"_sv];
|
|
||||||
static const CARD32 WM_TRANSIENT_FOR = g_atoms_name_to_id["WM_TRANSIENT_FOR"_sv];
|
|
||||||
static const CARD32 _NET_WM_WINDOW_TYPE = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE"_sv];
|
static const CARD32 _NET_WM_WINDOW_TYPE = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE"_sv];
|
||||||
static const CARD32 _NET_WM_WINDOW_TYPE_DIALOG = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_DIALOG"_sv];
|
static const CARD32 _NET_WM_WINDOW_TYPE_DIALOG = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_DIALOG"_sv];
|
||||||
static const CARD32 _NET_WM_WINDOW_TYPE_NORMAL = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_NORMAL"_sv];
|
static const CARD32 _NET_WM_WINDOW_TYPE_NORMAL = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_NORMAL"_sv];
|
||||||
static const CARD32 _NET_WM_WINDOW_TYPE_SPLASH = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_SPLASH"_sv];
|
static const CARD32 _NET_WM_WINDOW_TYPE_SPLASH = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_SPLASH"_sv];
|
||||||
static const CARD32 _NET_WM_WINDOW_TYPE_UTILITY = g_atoms_name_to_id["_NET_WM_WINDOW_TYPE_UTILITY"_sv];
|
|
||||||
|
|
||||||
PlatformWindowInfo info {
|
auto it = window.properties.find(_NET_WM_WINDOW_TYPE);
|
||||||
.parent = nullptr,
|
if (it == window.properties.end())
|
||||||
.type = WindowType::Normal,
|
return WindowType::Normal;
|
||||||
};
|
|
||||||
|
|
||||||
if (auto it = window.properties.find(_NET_WM_WINDOW_TYPE); it != window.properties.end())
|
if (it->value.type != ATOM || it->value.data.size() != sizeof(CARD32))
|
||||||
{
|
return WindowType::Normal;
|
||||||
if (it->value.type != ATOM || it->value.data.size() != sizeof(CARD32))
|
|
||||||
goto wm_window_type_done;
|
|
||||||
|
|
||||||
const CARD32 type = *reinterpret_cast<const CARD32*>(it->value.data.data());
|
const CARD32 type = *reinterpret_cast<const CARD32*>(it->value.data.data());
|
||||||
if (type == _NET_WM_WINDOW_TYPE_NORMAL)
|
if (type == _NET_WM_WINDOW_TYPE_NORMAL)
|
||||||
info.type = WindowType::Normal;
|
return WindowType::Normal;
|
||||||
else if (type == _NET_WM_WINDOW_TYPE_SPLASH || type == _NET_WM_WINDOW_TYPE_DIALOG)
|
if (type == _NET_WM_WINDOW_TYPE_SPLASH || type == _NET_WM_WINDOW_TYPE_DIALOG)
|
||||||
info.type = WindowType::Utility;
|
return WindowType::Utility;
|
||||||
else
|
return WindowType::Popup;
|
||||||
info.type = WindowType::Popup;
|
|
||||||
}
|
|
||||||
wm_window_type_done:
|
|
||||||
|
|
||||||
if (auto it = window.properties.find(WM_TRANSIENT_FOR); it != window.properties.end())
|
|
||||||
{
|
|
||||||
if (it->value.type != WINDOW || it->value.data.size() != sizeof(CARD32))
|
|
||||||
goto transitient_for_done;
|
|
||||||
|
|
||||||
const CARD32 wid = *reinterpret_cast<const CARD32*>(it->value.data.data());
|
|
||||||
|
|
||||||
auto it2 = g_objects.find(wid);
|
|
||||||
if (it2 == g_objects.end())
|
|
||||||
goto transitient_for_done;
|
|
||||||
if (it2->value->type != Object::Type::Window)
|
|
||||||
goto transitient_for_done;
|
|
||||||
|
|
||||||
// FIXME: support child windows
|
|
||||||
auto& window = it2->value->object.get<Object::Window>();
|
|
||||||
info.parent = window.platform_window.ptr();
|
|
||||||
}
|
|
||||||
transitient_for_done:
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<void> map_window(Client& client_info, WINDOW wid)
|
static BAN::ErrorOr<void> map_window(Client& client_info, WINDOW wid)
|
||||||
@@ -529,10 +531,13 @@ static BAN::ErrorOr<void> map_window(Client& client_info, WINDOW wid)
|
|||||||
if (window.width <= 10 || window.height <= 10)
|
if (window.width <= 10 || window.height <= 10)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto info = get_plaform_window_info(window);
|
TRY(window.double_buffer.resize(window.width * window.height));
|
||||||
|
for (auto& pixel : window.double_buffer)
|
||||||
|
pixel = window.background;
|
||||||
|
|
||||||
|
const auto type = get_plaform_window_info(window);
|
||||||
window.platform_window = TRY(g_platform_ops.create_window(
|
window.platform_window = TRY(g_platform_ops.create_window(
|
||||||
info.parent,
|
type,
|
||||||
info.type,
|
|
||||||
wid,
|
wid,
|
||||||
window.x,
|
window.x,
|
||||||
window.y,
|
window.y,
|
||||||
@@ -576,19 +581,7 @@ static BAN::ErrorOr<void> map_window(Client& client_info, WINDOW wid)
|
|||||||
if (is_visible(window.parent))
|
if (is_visible(window.parent))
|
||||||
TRY(send_visibility_events_recursively(client_info, wid, true));
|
TRY(send_visibility_events_recursively(client_info, wid, true));
|
||||||
|
|
||||||
{
|
TRY(send_exposure_events_recursive(wid));
|
||||||
xEvent event = { .u = {
|
|
||||||
.expose = {
|
|
||||||
.window = wid,
|
|
||||||
.x = 0,
|
|
||||||
.y = 0,
|
|
||||||
.width = static_cast<CARD16>(window.width),
|
|
||||||
.height = static_cast<CARD16>(window.height),
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
event.u.u.type = Expose;
|
|
||||||
TRY(window.send_event(event, ExposureMask));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -604,8 +597,8 @@ static BAN::ErrorOr<void> unmap_window(Client& client_info, WINDOW wid)
|
|||||||
|
|
||||||
window.mapped = false;
|
window.mapped = false;
|
||||||
|
|
||||||
if (window.platform_window)
|
window.double_buffer.clear();
|
||||||
window.platform_window.clear();
|
window.platform_window.clear();
|
||||||
|
|
||||||
if (is_visible(window.parent))
|
if (is_visible(window.parent))
|
||||||
TRY(send_visibility_events_recursively(client_info, wid, false));
|
TRY(send_visibility_events_recursively(client_info, wid, false));
|
||||||
@@ -757,7 +750,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
|
|||||||
if (wid == None)
|
if (wid == None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CURSOR cid = [&wid]() -> CURSOR {
|
const CURSOR cid = [](WINDOW wid) -> CURSOR {
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const auto& window = g_objects[wid]->object.get<Object::Window>();
|
const auto& window = g_objects[wid]->object.get<Object::Window>();
|
||||||
@@ -765,7 +758,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
|
|||||||
return window.cursor;
|
return window.cursor;
|
||||||
wid = window.parent;
|
wid = window.parent;
|
||||||
}
|
}
|
||||||
}();
|
}(wid);
|
||||||
|
|
||||||
static CURSOR active_cid = None;
|
static CURSOR active_cid = None;
|
||||||
if (cid == active_cid)
|
if (cid == active_cid)
|
||||||
@@ -863,8 +856,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("CreateWindow");
|
dprintln("CreateWindow");
|
||||||
dprintln(" depth: {}", request.depth);
|
dprintln(" depth: {}", request.depth);
|
||||||
dprintln(" wid: {}", request.wid);
|
dprintln(" wid: {h}", request.wid);
|
||||||
dprintln(" parent: {}", request.parent);
|
dprintln(" parent: {h}", request.parent);
|
||||||
dprintln(" x: {}", request.x);
|
dprintln(" x: {}", request.x);
|
||||||
dprintln(" y: {}", request.y);
|
dprintln(" y: {}", request.y);
|
||||||
dprintln(" width: {}", request.width);
|
dprintln(" width: {}", request.width);
|
||||||
@@ -990,7 +983,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xChangeWindowAttributesReq>(packet).value();
|
auto request = decode<xChangeWindowAttributesReq>(packet).value();
|
||||||
|
|
||||||
dprintln("ChangeWindowAttributes");
|
dprintln("ChangeWindowAttributes");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" valueMask: {8h}", request.valueMask);
|
dprintln(" valueMask: {8h}", request.valueMask);
|
||||||
|
|
||||||
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
||||||
@@ -1049,7 +1042,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("GetWindowAttributes");
|
dprintln("GetWindowAttributes");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
|
|
||||||
@@ -1086,7 +1079,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("DestroyWinow");
|
dprintln("DestroyWinow");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
(void)TRY_REF(get_window(client_info, wid, opcode));
|
(void)TRY_REF(get_window(client_info, wid, opcode));
|
||||||
TRY(destroy_window(client_info, wid));
|
TRY(destroy_window(client_info, wid));
|
||||||
@@ -1098,8 +1091,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xReparentWindowReq>(packet).value();
|
auto request = decode<xReparentWindowReq>(packet).value();
|
||||||
|
|
||||||
dprintln("ReparentWinow");
|
dprintln("ReparentWinow");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" parent: {}", request.parent);
|
dprintln(" parent: {h}", request.parent);
|
||||||
dprintln(" x: {}", request.x);
|
dprintln(" x: {}", request.x);
|
||||||
dprintln(" y: {}", request.y);
|
dprintln(" y: {}", request.y);
|
||||||
|
|
||||||
@@ -1169,7 +1162,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("MapWindow");
|
dprintln("MapWindow");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
(void)TRY_REF(get_window(client_info, wid, opcode));
|
(void)TRY_REF(get_window(client_info, wid, opcode));
|
||||||
TRY(map_window(client_info, wid));
|
TRY(map_window(client_info, wid));
|
||||||
@@ -1181,7 +1174,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("MapSubwindows");
|
dprintln("MapSubwindows");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
for (auto child_wid : window.children)
|
for (auto child_wid : window.children)
|
||||||
@@ -1194,7 +1187,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("UnmapWindow");
|
dprintln("UnmapWindow");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
(void)TRY_REF(get_window(client_info, wid, opcode));
|
(void)TRY_REF(get_window(client_info, wid, opcode));
|
||||||
TRY(unmap_window(client_info, wid));
|
TRY(unmap_window(client_info, wid));
|
||||||
@@ -1206,7 +1199,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("UnmapSubwindows");
|
dprintln("UnmapSubwindows");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
for (auto child_wid : window.children)
|
for (auto child_wid : window.children)
|
||||||
@@ -1219,7 +1212,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xConfigureWindowReq>(packet).value();
|
auto request = decode<xConfigureWindowReq>(packet).value();
|
||||||
|
|
||||||
dprintln("ConfigureWindow");
|
dprintln("ConfigureWindow");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
|
dprintln(" mask: {4h}", request.mask);
|
||||||
|
|
||||||
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
||||||
|
|
||||||
@@ -1228,7 +1222,6 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
uint32_t new_width = window.width;
|
uint32_t new_width = window.width;
|
||||||
uint32_t new_height = window.height;
|
uint32_t new_height = window.height;
|
||||||
|
|
||||||
dprintln(" mask:");
|
|
||||||
for (size_t i = 0; i < 7; i++)
|
for (size_t i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
if (!(request.mask & (1 << i)))
|
if (!(request.mask & (1 << i)))
|
||||||
@@ -1240,15 +1233,19 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
new_x = value;
|
new_x = value;
|
||||||
|
dprintln(" x: {}", value);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
new_y = value;
|
new_y = value;
|
||||||
|
dprintln(" y: {}", value);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
new_width = value;
|
new_width = value;
|
||||||
|
dprintln(" w: {}", value);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
new_height = value;
|
new_height = value;
|
||||||
|
dprintln(" h: {}", value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dprintln(" {4h}: {4h}", 1 << i, value);
|
dprintln(" {4h}: {4h}", 1 << i, value);
|
||||||
@@ -1256,7 +1253,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool send_configure = false;
|
bool should_send_configure_notify = false;
|
||||||
|
|
||||||
if (new_x != window.x || new_y != window.y)
|
if (new_x != window.x || new_y != window.y)
|
||||||
{
|
{
|
||||||
@@ -1269,7 +1266,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
{
|
{
|
||||||
window.x = new_x;
|
window.x = new_x;
|
||||||
window.y = new_y;
|
window.y = new_y;
|
||||||
send_configure = true;
|
should_send_configure_notify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1288,52 +1285,17 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
window.width = new_width;
|
window.width = new_width;
|
||||||
window.height = new_height;
|
window.height = new_height;
|
||||||
send_configure = true;
|
should_send_configure_notify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!send_configure)
|
if (!should_send_configure_notify)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
{
|
TRY(send_configure_notify(request.window));
|
||||||
xEvent event = { .u = {
|
|
||||||
.configureNotify = {
|
|
||||||
.event = request.window,
|
|
||||||
.window = request.window,
|
|
||||||
.aboveSibling = xFalse,
|
|
||||||
.x = static_cast<INT16>(window.x),
|
|
||||||
.y = static_cast<INT16>(window.y),
|
|
||||||
.width = static_cast<CARD16>(window.width),
|
|
||||||
.height = static_cast<CARD16>(window.height),
|
|
||||||
.borderWidth = 0,
|
|
||||||
.override = xFalse,
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
event.u.u.type = ConfigureNotify;
|
|
||||||
TRY(window.send_event(event, StructureNotifyMask));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& parent_object = *g_objects[window.parent];
|
if (is_visible(request.window))
|
||||||
ASSERT(parent_object.type == Object::Type::Window);
|
TRY(send_exposure_events_recursive(request.window));
|
||||||
auto& parent_window = parent_object.object.get<Object::Window>();
|
|
||||||
|
|
||||||
{
|
|
||||||
xEvent event = { .u = {
|
|
||||||
.configureNotify = {
|
|
||||||
.event = window.parent,
|
|
||||||
.window = request.window,
|
|
||||||
.aboveSibling = xFalse,
|
|
||||||
.x = static_cast<INT16>(window.x),
|
|
||||||
.y = static_cast<INT16>(window.y),
|
|
||||||
.width = static_cast<CARD16>(window.width),
|
|
||||||
.height = static_cast<CARD16>(window.height),
|
|
||||||
.borderWidth = 0,
|
|
||||||
.override = xFalse,
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
event.u.u.type = ConfigureNotify;
|
|
||||||
TRY(parent_window.send_event(event, SubstructureNotifyMask));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1342,7 +1304,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 drawable_id = packet.as_span<const uint32_t>()[1];
|
const CARD32 drawable_id = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("GetGeometry");
|
dprintln("GetGeometry");
|
||||||
dprintln(" drawable: {}", drawable_id);
|
dprintln(" drawable: {h}", drawable_id);
|
||||||
|
|
||||||
auto it = g_objects.find(drawable_id);
|
auto it = g_objects.find(drawable_id);
|
||||||
if (it == g_objects.end() || (it->value->type != Object::Type::Window && it->value->type != Object::Type::Pixmap))
|
if (it == g_objects.end() || (it->value->type != Object::Type::Window && it->value->type != Object::Type::Pixmap))
|
||||||
@@ -1365,15 +1327,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
CARD16 width, height;
|
CARD16 width, height;
|
||||||
CARD8 depth;
|
CARD8 depth;
|
||||||
|
|
||||||
if (drawable_id == g_root.windowId)
|
if (drawable.type == Object::Type::Window)
|
||||||
{
|
|
||||||
width = g_root.pixWidth;
|
|
||||||
height = g_root.pixHeight;
|
|
||||||
depth = g_root.rootDepth;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
else if (drawable.type == Object::Type::Window)
|
|
||||||
{
|
{
|
||||||
const auto& window = drawable.object.get<Object::Window>();
|
const auto& window = drawable.object.get<Object::Window>();
|
||||||
width = window.width;
|
width = window.width;
|
||||||
@@ -1417,7 +1371,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const auto wid = packet.as_span<const CARD32>()[1];
|
const auto wid = packet.as_span<const CARD32>()[1];
|
||||||
|
|
||||||
dprintln("QueryTree");
|
dprintln("QueryTree");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
|
|
||||||
@@ -1501,7 +1455,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("ChangeProperty");
|
dprintln("ChangeProperty");
|
||||||
dprintln(" mode: {}", request.mode);
|
dprintln(" mode: {}", request.mode);
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
||||||
dprintln(" type: {}", g_atoms_id_to_name[request.type]);
|
dprintln(" type: {}", g_atoms_id_to_name[request.type]);
|
||||||
dprintln(" format: {}", request.format);
|
dprintln(" format: {}", request.format);
|
||||||
@@ -1566,7 +1520,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xDeletePropertyReq>(packet).value();
|
auto request = decode<xDeletePropertyReq>(packet).value();
|
||||||
|
|
||||||
dprintln("DeleteProperty");
|
dprintln("DeleteProperty");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
||||||
|
|
||||||
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
|
||||||
@@ -1596,7 +1550,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("GetProperty");
|
dprintln("GetProperty");
|
||||||
dprintln(" c_delete: {}", request.c_delete);
|
dprintln(" c_delete: {}", request.c_delete);
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
|
||||||
dprintln(" type: {}", request.type);
|
dprintln(" type: {}", request.type);
|
||||||
dprintln(" longOffset: {}", request.longOffset);
|
dprintln(" longOffset: {}", request.longOffset);
|
||||||
@@ -1679,7 +1633,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("ListProperties");
|
dprintln("ListProperties");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
|
|
||||||
@@ -1703,7 +1657,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xSetSelectionOwnerReq>(packet).value();
|
auto request = decode<xSetSelectionOwnerReq>(packet).value();
|
||||||
|
|
||||||
dprintln("SetSelectionOwner");
|
dprintln("SetSelectionOwner");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" selection: {}", g_atoms_id_to_name[request.selection]);
|
dprintln(" selection: {}", g_atoms_id_to_name[request.selection]);
|
||||||
dprintln(" time: {}", request.time);
|
dprintln(" time: {}", request.time);
|
||||||
|
|
||||||
@@ -1759,7 +1713,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xConvertSelectionReq>(packet).value();
|
auto request = decode<xConvertSelectionReq>(packet).value();
|
||||||
|
|
||||||
dprintln("ConvertSelection");
|
dprintln("ConvertSelection");
|
||||||
dprintln(" requestor: {}", request.requestor);
|
dprintln(" requestor: {h}", request.requestor);
|
||||||
dprintln(" selection: {}", get_atom_name_safe(request.selection));
|
dprintln(" selection: {}", get_atom_name_safe(request.selection));
|
||||||
dprintln(" target: {}", get_atom_name_safe(request.target));
|
dprintln(" target: {}", get_atom_name_safe(request.target));
|
||||||
dprintln(" property: {}", get_atom_name_safe(request.property));
|
dprintln(" property: {}", get_atom_name_safe(request.property));
|
||||||
@@ -1846,8 +1800,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("GrabPointer");
|
dprintln("GrabPointer");
|
||||||
dprintln(" ownerEvents: {}", request.ownerEvents);
|
dprintln(" ownerEvents: {}", request.ownerEvents);
|
||||||
dprintln(" grabWindow: {}", request.grabWindow);
|
dprintln(" grabWindow: {h}", request.grabWindow);
|
||||||
dprintln(" eventMask: {}", request.eventMask);
|
dprintln(" eventMask: {h}", request.eventMask);
|
||||||
dprintln(" pointerMode: {}", request.pointerMode);
|
dprintln(" pointerMode: {}", request.pointerMode);
|
||||||
dprintln(" keyboardMode: {}", request.keyboardMode);
|
dprintln(" keyboardMode: {}", request.keyboardMode);
|
||||||
dprintln(" confineTo: {}", request.confineTo);
|
dprintln(" confineTo: {}", request.confineTo);
|
||||||
@@ -1913,7 +1867,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("GrabKeyboard");
|
dprintln("GrabKeyboard");
|
||||||
dprintln(" ownerEvents: {}", request.ownerEvents);
|
dprintln(" ownerEvents: {}", request.ownerEvents);
|
||||||
dprintln(" grabWindow: {}", request.grabWindow);
|
dprintln(" grabWindow: {h}", request.grabWindow);
|
||||||
dprintln(" pointerMode: {}", request.pointerMode);
|
dprintln(" pointerMode: {}", request.pointerMode);
|
||||||
dprintln(" keyboardMode: {}", request.keyboardMode);
|
dprintln(" keyboardMode: {}", request.keyboardMode);
|
||||||
dprintln(" time: {}", request.time);
|
dprintln(" time: {}", request.time);
|
||||||
@@ -1988,7 +1942,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
const CARD32 wid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("QueryPointer");
|
dprintln("QueryPointer");
|
||||||
dprintln(" window: {}", wid);
|
dprintln(" window: {h}", wid);
|
||||||
|
|
||||||
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
|
||||||
|
|
||||||
@@ -2035,8 +1989,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xTranslateCoordsReq>(packet).value();
|
auto request = decode<xTranslateCoordsReq>(packet).value();
|
||||||
|
|
||||||
dprintln("TranslateCoords");
|
dprintln("TranslateCoords");
|
||||||
dprintln(" src_wid: {}", request.srcWid);
|
dprintln(" src_wid: {h}", request.srcWid);
|
||||||
dprintln(" dst_wid: {}", request.dstWid);
|
dprintln(" dst_wid: {h}", request.dstWid);
|
||||||
dprintln(" src_x: {}", request.srcX);
|
dprintln(" src_x: {}", request.srcX);
|
||||||
dprintln(" src_y: {}", request.srcY);
|
dprintln(" src_y: {}", request.srcY);
|
||||||
|
|
||||||
@@ -2064,12 +2018,12 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xWarpPointerReq>(packet).value();
|
auto request = decode<xWarpPointerReq>(packet).value();
|
||||||
|
|
||||||
dprintln("WarpPointer");
|
dprintln("WarpPointer");
|
||||||
dprintln(" src_wid: {}", request.srcWid);
|
dprintln(" src_wid: {h}", request.srcWid);
|
||||||
dprintln(" src_x: {}", request.srcX);
|
dprintln(" src_x: {}", request.srcX);
|
||||||
dprintln(" src_y: {}", request.srcY);
|
dprintln(" src_y: {}", request.srcY);
|
||||||
dprintln(" src_w: {}", request.srcWidth);
|
dprintln(" src_w: {}", request.srcWidth);
|
||||||
dprintln(" src_h: {}", request.srcHeight);
|
dprintln(" src_h: {}", request.srcHeight);
|
||||||
dprintln(" dst_wid: {}", request.dstWid);
|
dprintln(" dst_wid: {h}", request.dstWid);
|
||||||
dprintln(" dst_x: {}", request.dstX);
|
dprintln(" dst_x: {}", request.dstX);
|
||||||
dprintln(" dst_y: {}", request.dstY);
|
dprintln(" dst_y: {}", request.dstY);
|
||||||
|
|
||||||
@@ -2139,8 +2093,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("CreatePixmap");
|
dprintln("CreatePixmap");
|
||||||
dprintln(" depth: {}", request.depth);
|
dprintln(" depth: {}", request.depth);
|
||||||
dprintln(" pid: {}", request.pid);
|
dprintln(" pid: {h}", request.pid);
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" width: {}", request.width);
|
dprintln(" width: {}", request.width);
|
||||||
dprintln(" height: {}", request.height);
|
dprintln(" height: {}", request.height);
|
||||||
|
|
||||||
@@ -2174,7 +2128,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 pid = packet.as_span<const uint32_t>()[1];
|
const CARD32 pid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("FreePixmap");
|
dprintln("FreePixmap");
|
||||||
dprintln(" pixmap: {}", pid);
|
dprintln(" pixmap: {h}", pid);
|
||||||
|
|
||||||
(void)TRY_REF(get_pixmap(client_info, pid, opcode));
|
(void)TRY_REF(get_pixmap(client_info, pid, opcode));
|
||||||
client_info.objects.remove(pid);
|
client_info.objects.remove(pid);
|
||||||
@@ -2187,14 +2141,14 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xCreateGCReq>(packet).value();
|
auto request = decode<xCreateGCReq>(packet).value();
|
||||||
|
|
||||||
dprintln("CreateGC");
|
dprintln("CreateGC");
|
||||||
dprintln(" drawable {}", request.drawable);
|
dprintln(" drawable {h}", request.drawable);
|
||||||
dprintln(" gc {}", request.gc);
|
dprintln(" gc {}", request.gc);
|
||||||
dprintln(" mask {8h}", request.mask);
|
dprintln(" mask {8h}", request.mask);
|
||||||
|
|
||||||
// TODO: support invisible background
|
// TODO: support invisible background
|
||||||
|
|
||||||
uint32_t foreground = 0x000000;
|
uint32_t foreground = 0x000000;
|
||||||
uint32_t background = 0x000000;
|
uint32_t background = 0xFFFFFF;
|
||||||
uint16_t line_width = 0;
|
uint16_t line_width = 0;
|
||||||
uint32_t font = None;
|
uint32_t font = None;
|
||||||
bool graphics_exposures = true;
|
bool graphics_exposures = true;
|
||||||
@@ -2269,7 +2223,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xChangeGCReq>(packet).value();
|
auto request = decode<xChangeGCReq>(packet).value();
|
||||||
|
|
||||||
dprintln("ChangeGC");
|
dprintln("ChangeGC");
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {h}", request.gc);
|
||||||
dprintln(" mask: {8h}", request.mask);
|
dprintln(" mask: {8h}", request.mask);
|
||||||
|
|
||||||
auto& object = *g_objects[request.gc];
|
auto& object = *g_objects[request.gc];
|
||||||
@@ -2333,7 +2287,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xSetClipRectanglesReq>(packet).value();
|
auto request = decode<xSetClipRectanglesReq>(packet).value();
|
||||||
|
|
||||||
dprintln("SetClipRectangles");
|
dprintln("SetClipRectangles");
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {h}", request.gc);
|
||||||
dprintln(" ordering: {}", request.ordering);
|
dprintln(" ordering: {}", request.ordering);
|
||||||
dprintln(" xOrigin: {}", request.xOrigin);
|
dprintln(" xOrigin: {}", request.xOrigin);
|
||||||
dprintln(" yOrigin: {}", request.yOrigin);
|
dprintln(" yOrigin: {}", request.yOrigin);
|
||||||
@@ -2361,7 +2315,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const CARD32 gc = packet.as_span<const uint32_t>()[1];
|
const CARD32 gc = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("FreeGC");
|
dprintln("FreeGC");
|
||||||
dprintln(" gc: {}", gc);
|
dprintln(" gc: {h}", gc);
|
||||||
|
|
||||||
(void)TRY_REF(get_gc(client_info, gc, opcode));
|
(void)TRY_REF(get_gc(client_info, gc, opcode));
|
||||||
client_info.objects.remove(gc);
|
client_info.objects.remove(gc);
|
||||||
@@ -2375,7 +2329,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("ClearArea");
|
dprintln("ClearArea");
|
||||||
dprintln(" exposures: {}", request.exposures);
|
dprintln(" exposures: {}", request.exposures);
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {h}", request.window);
|
||||||
dprintln(" x: {}", request.x);
|
dprintln(" x: {}", request.x);
|
||||||
dprintln(" y: {}", request.y);
|
dprintln(" y: {}", request.y);
|
||||||
dprintln(" width: {}", request.width);
|
dprintln(" width: {}", request.width);
|
||||||
@@ -2409,9 +2363,9 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xCopyAreaReq>(packet).value();
|
auto request = decode<xCopyAreaReq>(packet).value();
|
||||||
|
|
||||||
dprintln("CopyArea");
|
dprintln("CopyArea");
|
||||||
dprintln(" srcDrawable: {}", request.srcDrawable);
|
dprintln(" srcDrawable: {h}", request.srcDrawable);
|
||||||
dprintln(" dstDrawable: {}", request.dstDrawable);
|
dprintln(" dstDrawable: {h}", request.dstDrawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {h}", request.gc);
|
||||||
dprintln(" srcX: {}", request.srcX);
|
dprintln(" srcX: {}", request.srcX);
|
||||||
dprintln(" srcY: {}", request.srcY);
|
dprintln(" srcY: {}", request.srcY);
|
||||||
dprintln(" dstX: {}", request.dstX);
|
dprintln(" dstX: {}", request.dstX);
|
||||||
@@ -2504,8 +2458,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xPutImageReq>(packet).value();
|
auto request = decode<xPutImageReq>(packet).value();
|
||||||
|
|
||||||
dprintln("PutImage");
|
dprintln("PutImage");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {h}", request.gc);
|
||||||
dprintln(" format: {}", request.format);
|
dprintln(" format: {}", request.format);
|
||||||
dprintln(" depth: {}", request.depth);
|
dprintln(" depth: {}", request.depth);
|
||||||
dprintln(" dstX: {}", request.dstX);
|
dprintln(" dstX: {}", request.dstX);
|
||||||
@@ -2553,7 +2507,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xGetImageReq>(packet).value();
|
auto request = decode<xGetImageReq>(packet).value();
|
||||||
|
|
||||||
dprintln("GetImage");
|
dprintln("GetImage");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" format: {}", request.format);
|
dprintln(" format: {}", request.format);
|
||||||
dprintln(" x: {}", request.x);
|
dprintln(" x: {}", request.x);
|
||||||
dprintln(" y: {}", request.y);
|
dprintln(" y: {}", request.y);
|
||||||
@@ -2724,7 +2678,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xCreateCursorReq>(packet).value();
|
auto request = decode<xCreateCursorReq>(packet).value();
|
||||||
|
|
||||||
dprintln("CreateCursor");
|
dprintln("CreateCursor");
|
||||||
dprintln(" cid: {}", request.cid);
|
dprintln(" cid: {h}", request.cid);
|
||||||
dprintln(" source: {}", request.source);
|
dprintln(" source: {}", request.source);
|
||||||
dprintln(" mask: {}", request.mask);
|
dprintln(" mask: {}", request.mask);
|
||||||
dprintln(" foreRed: {}", request.foreRed);
|
dprintln(" foreRed: {}", request.foreRed);
|
||||||
@@ -2795,7 +2749,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
const auto cid = packet.as_span<const uint32_t>()[1];
|
const auto cid = packet.as_span<const uint32_t>()[1];
|
||||||
|
|
||||||
dprintln("FreeCursor");
|
dprintln("FreeCursor");
|
||||||
dprintln(" cid: {}", cid);
|
dprintln(" cid: {h}", cid);
|
||||||
|
|
||||||
client_info.objects.remove(cid);
|
client_info.objects.remove(cid);
|
||||||
g_objects.remove(cid);
|
g_objects.remove(cid);
|
||||||
@@ -2808,7 +2762,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
dprintln("QueryBestSize");
|
dprintln("QueryBestSize");
|
||||||
dprintln(" class: {}", request.c_class);
|
dprintln(" class: {}", request.c_class);
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" width: {}", request.width);
|
dprintln(" width: {}", request.width);
|
||||||
dprintln(" height: {}", request.height);
|
dprintln(" height: {}", request.height);
|
||||||
|
|
||||||
@@ -2899,8 +2853,19 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
dprintln(" firstKeyCode: {}", request.firstKeyCode);
|
dprintln(" firstKeyCode: {}", request.firstKeyCode);
|
||||||
dprintln(" count: {}", request.count);
|
dprintln(" count: {}", request.count);
|
||||||
|
|
||||||
ASSERT(g_keymap_min_keycode <= request.firstKeyCode);
|
if (request.firstKeyCode < g_keymap_min_keycode || request.firstKeyCode + request.count - 1 > g_keymap_max_keycode)
|
||||||
ASSERT(g_keymap_max_keycode >= request.firstKeyCode + request.count - 1);
|
{
|
||||||
|
xError error {
|
||||||
|
.type = X_Error,
|
||||||
|
.errorCode = BadValue,
|
||||||
|
.sequenceNumber = client_info.sequence,
|
||||||
|
.resourceID = 0, // TODO: should this be something meaningful?
|
||||||
|
.minorCode = 0,
|
||||||
|
.majorCode = opcode,
|
||||||
|
};
|
||||||
|
TRY(encode(client_info.output_buffer, error));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
xGetKeyboardMappingReply reply {
|
xGetKeyboardMappingReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
@@ -2909,10 +2874,10 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
.length = static_cast<CARD32>(request.count * g_keymap_layers),
|
.length = static_cast<CARD32>(request.count * g_keymap_layers),
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
TRY(encode(client_info.output_buffer, BAN::Span(
|
||||||
for (size_t i = 0; i < request.count; i++)
|
g_keymap + request.firstKeyCode - g_keymap_min_keycode,
|
||||||
for (size_t j = 0; j < g_keymap_layers; j++)
|
request.count
|
||||||
TRY(encode<CARD32>(client_info.output_buffer, g_keymap[request.firstKeyCode + i][j]));
|
)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2953,36 +2918,12 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
xGetModifierMappingReply reply {
|
xGetModifierMappingReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.numKeyPerModifier = 2,
|
.numKeyPerModifier = g_modifier_layers,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 4,
|
.length = 2 * g_modifier_layers,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
TRY(encode(client_info.output_buffer, g_modifier_map));
|
||||||
using LibInput::keycode_normal;
|
|
||||||
|
|
||||||
// shift
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(3, 0))); // lshift
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(3, 12))); // rshift
|
|
||||||
|
|
||||||
// lock
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(2, 0))); // caps lock
|
|
||||||
TRY(encode(client_info.output_buffer, static_cast<uint8_t>(0)));
|
|
||||||
|
|
||||||
// control
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(4, 0))); // lcrtl
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(4, 6))); // rctrl
|
|
||||||
|
|
||||||
// mod1
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(4, 2))); // lalt
|
|
||||||
TRY(encode(client_info.output_buffer, keycode_normal(4, 5))); // ralt
|
|
||||||
|
|
||||||
// mod2 -> mod5
|
|
||||||
for (size_t i = 2; i <= 5; i++)
|
|
||||||
{
|
|
||||||
TRY(encode(client_info.output_buffer, static_cast<uint8_t>(0)));
|
|
||||||
TRY(encode(client_info.output_buffer, static_cast<uint8_t>(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ BAN::ErrorOr<void> setup_client_conneciton(Client& client_info, const xConnClien
|
|||||||
BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet);
|
BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet);
|
||||||
|
|
||||||
void invalidate_window(WINDOW wid, int32_t x, int32_t y, int32_t w, int32_t h);
|
void invalidate_window(WINDOW wid, int32_t x, int32_t y, int32_t w, int32_t h);
|
||||||
void send_exposure_recursive(WINDOW wid);
|
|
||||||
|
BAN::ErrorOr<void> send_configure_notify(WINDOW wid);
|
||||||
|
BAN::ErrorOr<void> send_exposure_events_recursive(WINDOW wid);
|
||||||
|
|
||||||
void update_cursor(WINDOW wid, int32_t x, int32_t y);
|
void update_cursor(WINDOW wid, int32_t x, int32_t y);
|
||||||
|
|
||||||
@@ -16,7 +18,8 @@ WINDOW find_child_window(WINDOW wid, int32_t& x, int32_t& y);
|
|||||||
|
|
||||||
xPoint get_window_position(WINDOW wid);
|
xPoint get_window_position(WINDOW wid);
|
||||||
|
|
||||||
static constexpr uint32_t COLOR_INVISIBLE = 0x69000000;
|
// random number with alpha 0 :D
|
||||||
|
static constexpr uint32_t COLOR_INVISIBLE = 0x00b205AF;
|
||||||
|
|
||||||
extern CARD16 g_keymask;
|
extern CARD16 g_keymask;
|
||||||
extern CARD16 g_butmask;
|
extern CARD16 g_butmask;
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ set(XBANAN_SOURCES
|
|||||||
Extensions.cpp
|
Extensions.cpp
|
||||||
ExtBigReg.cpp
|
ExtBigReg.cpp
|
||||||
ExtRANDR.cpp
|
ExtRANDR.cpp
|
||||||
|
ExtXRes.cpp
|
||||||
Font.cpp
|
Font.cpp
|
||||||
Image.cpp
|
Image.cpp
|
||||||
Keymap.cpp
|
Keymap.cpp
|
||||||
SafeGetters.cpp
|
SafeGetters.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(FONT_PATH ${CMAKE_SOURCE_DIR}/fonts CACHE STRING "path to X11 fonts")
|
||||||
|
|
||||||
option(ENABLE_GLX "enable glx extension" ON)
|
option(ENABLE_GLX "enable glx extension" ON)
|
||||||
if(ENABLE_GLX)
|
if(ENABLE_GLX)
|
||||||
list(APPEND XBANAN_SOURCES ExtGLX.cpp)
|
list(APPEND XBANAN_SOURCES ExtGLX.cpp)
|
||||||
@@ -22,13 +25,6 @@ if(ENABLE_SHM)
|
|||||||
list(APPEND XBANAN_SOURCES ExtSHM.cpp)
|
list(APPEND XBANAN_SOURCES ExtSHM.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(PLATFORM "banan-os" CACHE STRING "target platform")
|
|
||||||
|
|
||||||
set(VALID_PLATFORMS "banan-os" "SDL3")
|
|
||||||
if(NOT PLATFORM IN_LIST VALID_PLATFORMS)
|
|
||||||
message(FATAL_ERROR "platform \"${PLATFORM}\" not known, valid platforms are ${VALID_PLATFORMS}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(PLATFORM STREQUAL "banan-os")
|
if(PLATFORM STREQUAL "banan-os")
|
||||||
list(APPEND XBANAN_SOURCES banan-os/banan-os.cpp)
|
list(APPEND XBANAN_SOURCES banan-os/banan-os.cpp)
|
||||||
elseif(PLATFORM STREQUAL "SDL3")
|
elseif(PLATFORM STREQUAL "SDL3")
|
||||||
@@ -38,10 +34,12 @@ endif()
|
|||||||
add_executable(xbanan ${XBANAN_SOURCES})
|
add_executable(xbanan ${XBANAN_SOURCES})
|
||||||
banan_link_library(xbanan ban)
|
banan_link_library(xbanan ban)
|
||||||
banan_link_library(xbanan libdeflate)
|
banan_link_library(xbanan libdeflate)
|
||||||
banan_link_library(xbanan libinput)
|
|
||||||
|
target_compile_definitions(xbanan PRIVATE FONT_PATH="${FONT_PATH}")
|
||||||
|
|
||||||
if(PLATFORM STREQUAL "banan-os")
|
if(PLATFORM STREQUAL "banan-os")
|
||||||
banan_link_library(xbanan libgui)
|
banan_link_library(xbanan libgui)
|
||||||
|
banan_link_library(xbanan libinput)
|
||||||
elseif(PLATFORM STREQUAL "SDL3")
|
elseif(PLATFORM STREQUAL "SDL3")
|
||||||
find_package(SDL3 REQUIRED)
|
find_package(SDL3 REQUIRED)
|
||||||
banan_link_library(xbanan SDL3::SDL3)
|
banan_link_library(xbanan SDL3::SDL3)
|
||||||
@@ -55,7 +53,4 @@ target_compile_options(xbanan PRIVATE
|
|||||||
-Wno-unused-but-set-variable
|
-Wno-unused-but-set-variable
|
||||||
)
|
)
|
||||||
|
|
||||||
#target_compile_options(xbanan PRIVATE -fsanitize=address)
|
|
||||||
#target_link_options(xbanan PRIVATE -fsanitize=address)
|
|
||||||
|
|
||||||
install(TARGETS xbanan OPTIONAL)
|
install(TARGETS xbanan OPTIONAL)
|
||||||
|
|||||||
@@ -66,8 +66,11 @@ struct Object
|
|||||||
|
|
||||||
uint32_t background { 0 };
|
uint32_t background { 0 };
|
||||||
|
|
||||||
|
bool platform_window_invalidated { false };
|
||||||
BAN::UniqPtr<PlatformWindow> platform_window;
|
BAN::UniqPtr<PlatformWindow> platform_window;
|
||||||
|
|
||||||
|
BAN::Vector<uint32_t> double_buffer;
|
||||||
|
|
||||||
BAN::HashMap<Client*, uint32_t> event_masks;
|
BAN::HashMap<Client*, uint32_t> event_masks;
|
||||||
|
|
||||||
BAN::HashMap<ATOM, Property> properties;
|
BAN::HashMap<ATOM, Property> properties;
|
||||||
@@ -143,6 +146,7 @@ struct Client
|
|||||||
bool has_epollout { false };
|
bool has_epollout { false };
|
||||||
bool has_bigrequests { false };
|
bool has_bigrequests { false };
|
||||||
CARD16 sequence { 0 };
|
CARD16 sequence { 0 };
|
||||||
|
BAN::Optional<uint32_t> pid;
|
||||||
BAN::Vector<uint8_t> input_buffer;
|
BAN::Vector<uint8_t> input_buffer;
|
||||||
BAN::Vector<uint8_t> output_buffer;
|
BAN::Vector<uint8_t> output_buffer;
|
||||||
BAN::HashSet<CARD32> objects;
|
BAN::HashSet<CARD32> objects;
|
||||||
@@ -160,6 +164,12 @@ struct EpollThingy
|
|||||||
BAN::Variant<Client, void*> value;
|
BAN::Variant<Client, void*> value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DisplayInfo
|
||||||
|
{
|
||||||
|
int32_t x, y;
|
||||||
|
uint32_t w, h;
|
||||||
|
};
|
||||||
|
|
||||||
extern const xPixmapFormat g_formats[6];
|
extern const xPixmapFormat g_formats[6];
|
||||||
extern const xDepth g_depth;
|
extern const xDepth g_depth;
|
||||||
extern const xVisualType g_visual;
|
extern const xVisualType g_visual;
|
||||||
@@ -175,3 +185,7 @@ extern int g_epoll_fd;
|
|||||||
extern BAN::HashMap<int, EpollThingy> g_epoll_thingies;
|
extern BAN::HashMap<int, EpollThingy> g_epoll_thingies;
|
||||||
|
|
||||||
extern int g_server_grabber_fd;
|
extern int g_server_grabber_fd;
|
||||||
|
|
||||||
|
extern BAN::Vector<DisplayInfo> g_displays;
|
||||||
|
|
||||||
|
extern CARD32 g_next_global_id;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ BAN::ErrorOr<void> poly_line(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xPolyLineReq>(packet).value();
|
auto request = decode<xPolyLineReq>(packet).value();
|
||||||
|
|
||||||
dprintln("PolyLine");
|
dprintln("PolyLine");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {}", request.gc);
|
||||||
dprintln(" coordMode: {}", request.coordMode);
|
dprintln(" coordMode: {}", request.coordMode);
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ BAN::ErrorOr<void> poly_segment(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xPolySegmentReq>(packet).value();
|
auto request = decode<xPolySegmentReq>(packet).value();
|
||||||
|
|
||||||
dprintln("PolySegment");
|
dprintln("PolySegment");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {}", request.gc);
|
||||||
|
|
||||||
auto [out_data_u32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolySegment));
|
auto [out_data_u32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolySegment));
|
||||||
@@ -203,7 +203,7 @@ BAN::ErrorOr<void> fill_poly(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xFillPolyReq>(packet).value();
|
auto request = decode<xFillPolyReq>(packet).value();
|
||||||
|
|
||||||
dprintln("FillPoly");
|
dprintln("FillPoly");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {}", request.gc);
|
||||||
dprintln(" shape: {}", request.shape);
|
dprintln(" shape: {}", request.shape);
|
||||||
dprintln(" coordMode: {}", request.coordMode);
|
dprintln(" coordMode: {}", request.coordMode);
|
||||||
@@ -278,7 +278,7 @@ BAN::ErrorOr<void> poly_fill_rectangle(Client& client_info, BAN::ConstByteSpan p
|
|||||||
auto request = decode<xPolyFillRectangleReq>(packet).value();
|
auto request = decode<xPolyFillRectangleReq>(packet).value();
|
||||||
|
|
||||||
dprintln("PolyFillRectangle");
|
dprintln("PolyFillRectangle");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {}", request.gc);
|
||||||
|
|
||||||
auto [out_data_u32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolyFillRectangle));
|
auto [out_data_u32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolyFillRectangle));
|
||||||
@@ -320,7 +320,7 @@ BAN::ErrorOr<void> poly_fill_arc(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
auto request = decode<xPolyFillArcReq>(packet).value();
|
auto request = decode<xPolyFillArcReq>(packet).value();
|
||||||
|
|
||||||
dprintln("PolyFillArc");
|
dprintln("PolyFillArc");
|
||||||
dprintln(" drawable: {}", request.drawable);
|
dprintln(" drawable: {h}", request.drawable);
|
||||||
dprintln(" gc: {}", request.gc);
|
dprintln(" gc: {}", request.gc);
|
||||||
|
|
||||||
auto [out_data_32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolyFillArc));
|
auto [out_data_32, out_w, out_h, _] = TRY(get_drawable_info(client_info, request.drawable, X_PolyFillArc));
|
||||||
|
|||||||
@@ -75,69 +75,26 @@ void on_window_close_event(WINDOW wid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_window_configure(WINDOW wid, Object::Window& window)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
xEvent event = { .u = {
|
|
||||||
.configureNotify = {
|
|
||||||
.event = wid,
|
|
||||||
.window = wid,
|
|
||||||
.aboveSibling = xFalse,
|
|
||||||
.x = static_cast<INT16>(window.x),
|
|
||||||
.y = static_cast<INT16>(window.y),
|
|
||||||
.width = static_cast<CARD16>(window.width),
|
|
||||||
.height = static_cast<CARD16>(window.height),
|
|
||||||
.borderWidth = 0,
|
|
||||||
.override = xFalse,
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
event.u.u.type = ConfigureNotify;
|
|
||||||
MUST(window.send_event(event, StructureNotifyMask));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& parent_object = *g_objects[window.parent];
|
|
||||||
ASSERT(parent_object.type == Object::Type::Window);
|
|
||||||
auto& parent_window = parent_object.object.get<Object::Window>();
|
|
||||||
|
|
||||||
{
|
|
||||||
xEvent event = { .u = {
|
|
||||||
.configureNotify = {
|
|
||||||
.event = window.parent,
|
|
||||||
.window = wid,
|
|
||||||
.aboveSibling = xFalse,
|
|
||||||
.x = static_cast<INT16>(window.x),
|
|
||||||
.y = static_cast<INT16>(window.y),
|
|
||||||
.width = static_cast<CARD16>(window.width),
|
|
||||||
.height = static_cast<CARD16>(window.height),
|
|
||||||
.borderWidth = 0,
|
|
||||||
.override = xFalse,
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
event.u.u.type = ConfigureNotify;
|
|
||||||
MUST(parent_window.send_event(event, SubstructureNotifyMask));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_window_resize_event(WINDOW wid, uint32_t new_width, uint32_t new_height)
|
void on_window_resize_event(WINDOW wid, uint32_t new_width, uint32_t new_height)
|
||||||
{
|
{
|
||||||
auto& object = *g_objects[wid];
|
auto& object = *g_objects[wid];
|
||||||
ASSERT(object.type == Object::Type::Window);
|
ASSERT(object.type == Object::Type::Window);
|
||||||
auto& window = object.object.get<Object::Window>();
|
auto& window = object.object.get<Object::Window>();
|
||||||
|
|
||||||
{
|
window.width = new_width;
|
||||||
window.width = new_width;
|
window.height = new_height;
|
||||||
window.height = new_height;
|
|
||||||
|
|
||||||
MUST(window.pixels.resize(new_width * new_height));
|
MUST(window.pixels.resize(new_width * new_height));
|
||||||
for (auto& pixel : window.pixels)
|
for (auto& pixel : window.pixels)
|
||||||
pixel = window.background;
|
pixel = window.background;
|
||||||
}
|
|
||||||
|
|
||||||
send_window_configure(wid, window);
|
MUST(window.double_buffer.resize(new_width * new_height));
|
||||||
|
for (auto& pixel : window.double_buffer)
|
||||||
|
pixel = window.background;
|
||||||
|
|
||||||
send_exposure_recursive(wid);
|
MUST(send_configure_notify(wid));
|
||||||
|
|
||||||
invalidate_window(wid, 0, 0, window.width, window.height);
|
MUST(send_exposure_events_recursive(wid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_window_move_event(WINDOW wid, int32_t x, int32_t y)
|
void on_window_move_event(WINDOW wid, int32_t x, int32_t y)
|
||||||
@@ -149,7 +106,7 @@ void on_window_move_event(WINDOW wid, int32_t x, int32_t y)
|
|||||||
window.x = x;
|
window.x = x;
|
||||||
window.y = y;
|
window.y = y;
|
||||||
|
|
||||||
send_window_configure(wid, window);
|
MUST(send_configure_notify(wid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_window_focus_event(WINDOW wid, bool focused)
|
void on_window_focus_event(WINDOW wid, bool focused)
|
||||||
@@ -553,19 +510,16 @@ void on_mouse_button_event(WINDOW wid, uint8_t xbutton, bool pressed)
|
|||||||
void on_key_event(WINDOW wid, uint8_t scancode, uint8_t xmod, bool pressed)
|
void on_key_event(WINDOW wid, uint8_t scancode, uint8_t xmod, bool pressed)
|
||||||
{
|
{
|
||||||
const uint8_t xkeycode = scancode + g_keymap_min_keycode;
|
const uint8_t xkeycode = scancode + g_keymap_min_keycode;
|
||||||
if (xkeycode < g_keymap_min_keycode)
|
if (xkeycode < g_keymap_min_keycode || xkeycode > g_keymap_max_keycode)
|
||||||
{
|
|
||||||
dwarnln("cannot send keycode {}", xkeycode);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const uint8_t byte = xkeycode / 8;
|
const uint8_t byte = xkeycode / 8;
|
||||||
const uint8_t bit = xkeycode % 8;
|
const uint8_t mask = 1 << (xkeycode % 8);
|
||||||
if (pressed)
|
if (pressed)
|
||||||
g_pressed_keys[byte] |= 1 << bit;
|
g_pressed_keys[byte] |= mask;
|
||||||
else
|
else
|
||||||
g_pressed_keys[byte] &= ~(1 << bit);
|
g_pressed_keys[byte] &= ~mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto old_state = g_keymask | g_butmask;
|
const auto old_state = g_keymask | g_butmask;
|
||||||
@@ -580,3 +534,26 @@ void on_key_event(WINDOW wid, uint8_t scancode, uint8_t xmod, bool pressed)
|
|||||||
old_state
|
old_state
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_keymap_changed()
|
||||||
|
{
|
||||||
|
for (auto& [id, object] : g_objects)
|
||||||
|
{
|
||||||
|
if (object->type != Object::Type::Window)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto& client_info = object->object.get<Object::Window>().owner;
|
||||||
|
|
||||||
|
xEvent event {};
|
||||||
|
event.u.u.type = MappingNotify;
|
||||||
|
event.u.u.sequenceNumber = client_info.sequence;
|
||||||
|
|
||||||
|
event.u.mappingNotify.request = MappingKeyboard,
|
||||||
|
event.u.mappingNotify.firstKeyCode = g_keymap_min_keycode,
|
||||||
|
event.u.mappingNotify.count = g_keymap_size,
|
||||||
|
MUST(encode(client_info.output_buffer, event));
|
||||||
|
|
||||||
|
event.u.mappingNotify.request = MappingModifier;
|
||||||
|
MUST(encode(client_info.output_buffer, event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,3 +15,5 @@ void on_window_leave_event(WINDOW wid);
|
|||||||
void on_mouse_move_event(WINDOW wid, int32_t x, int32_t y);
|
void on_mouse_move_event(WINDOW wid, int32_t x, int32_t y);
|
||||||
void on_mouse_button_event(WINDOW wid, uint8_t xbutton, bool pressed);
|
void on_mouse_button_event(WINDOW wid, uint8_t xbutton, bool pressed);
|
||||||
void on_key_event(WINDOW wid, uint8_t scancode, uint8_t xmod, bool pressed);
|
void on_key_event(WINDOW wid, uint8_t scancode, uint8_t xmod, bool pressed);
|
||||||
|
|
||||||
|
void on_keymap_changed();
|
||||||
|
|||||||
@@ -6,12 +6,64 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
struct RANDRDisplay
|
||||||
|
{
|
||||||
|
CARD32 crtc_id;
|
||||||
|
CARD32 output_id;
|
||||||
|
CARD32 mode_id;
|
||||||
|
ATOM name_atom;
|
||||||
|
BAN::String output_str;
|
||||||
|
BAN::String mode_str;
|
||||||
|
const DisplayInfo& info;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BAN::Vector<RANDRDisplay> s_randr_displays;
|
||||||
|
static CARD32 s_timestamp { 0 };
|
||||||
|
|
||||||
|
static void initialize_displays()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < g_displays.size(); i++)
|
||||||
|
{
|
||||||
|
auto name = MUST(BAN::String::formatted("B-OUT-{}", i));
|
||||||
|
|
||||||
|
const auto name_atom = g_atom_value++;
|
||||||
|
MUST(g_atoms_name_to_id.insert(name, name_atom));
|
||||||
|
MUST(g_atoms_id_to_name.insert(name_atom, name));
|
||||||
|
|
||||||
|
MUST(s_randr_displays.push_back({
|
||||||
|
.crtc_id = g_next_global_id++,
|
||||||
|
.output_id = g_next_global_id++,
|
||||||
|
.mode_id = g_next_global_id++,
|
||||||
|
.name_atom = name_atom,
|
||||||
|
.output_str = BAN::move(name),
|
||||||
|
.mode_str = MUST(BAN::String::formatted("{}x{}", g_displays[i].w, g_displays[i].h)),
|
||||||
|
.info = g_displays[i],
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
s_timestamp = time(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const RANDRDisplay& find_display_by_output(CARD32 output)
|
||||||
|
{
|
||||||
|
for (const auto& display : s_randr_displays)
|
||||||
|
if (display.output_id == output)
|
||||||
|
return display;
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const RANDRDisplay& find_display_by_crtc(CARD32 crtc)
|
||||||
|
{
|
||||||
|
for (const auto& display : s_randr_displays)
|
||||||
|
if (display.crtc_id == crtc)
|
||||||
|
return display;
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packet)
|
static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpan packet)
|
||||||
{
|
{
|
||||||
static CARD32 crtc_id = 5;
|
if (s_randr_displays.empty())
|
||||||
static CARD32 output_id = 6;
|
initialize_displays();
|
||||||
static CARD32 mode_id = 7;
|
|
||||||
static CARD32 timestamp = time(nullptr);
|
|
||||||
|
|
||||||
static xRenderTransform transform {
|
static xRenderTransform transform {
|
||||||
1 << 16, 0, 0,
|
1 << 16, 0, 0,
|
||||||
@@ -61,14 +113,14 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
.setOfRotations = RR_Rotate_0,
|
.setOfRotations = RR_Rotate_0,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 3,
|
.length = 3,
|
||||||
.root = g_root.windowId,
|
.root = g_root.windowId,
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.configTimestamp = timestamp,
|
.configTimestamp = s_timestamp,
|
||||||
.nSizes = 1,
|
.nSizes = 1,
|
||||||
.sizeID = 0,
|
.sizeID = 0,
|
||||||
.rotation = RR_Rotate_0,
|
.rotation = RR_Rotate_0,
|
||||||
.rate = 60,
|
.rate = 60,
|
||||||
.nrateEnts = 1,
|
.nrateEnts = 1,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -115,55 +167,63 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln("RRGetScreenResources{}", current ? "Current" : "");
|
dprintln("RRGetScreenResources{}", current ? "Current" : "");
|
||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {}", request.window);
|
||||||
|
|
||||||
const auto mode_name = TRY(BAN::String::formatted("{}x{}", g_root.pixWidth, g_root.pixHeight));
|
size_t mode_name_bytes = 0;
|
||||||
|
for (const auto& display : s_randr_displays)
|
||||||
|
mode_name_bytes += display.mode_str.size();
|
||||||
|
|
||||||
xRRGetScreenResourcesReply reply {
|
xRRGetScreenResourcesReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = static_cast<CARD32>(1 + 1 + 8 + (mode_name.size() + 3) / 4),
|
.length = static_cast<CARD32>(s_randr_displays.size() * (1 + 1 + 8) + (mode_name_bytes + 3) / 4),
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.configTimestamp = timestamp,
|
.configTimestamp = s_timestamp,
|
||||||
.nCrtcs = 1,
|
.nCrtcs = static_cast<CARD16>(s_randr_displays.size()),
|
||||||
.nOutputs = 1,
|
.nOutputs = static_cast<CARD16>(s_randr_displays.size()),
|
||||||
.nModes = 1,
|
.nModes = static_cast<CARD16>(s_randr_displays.size()),
|
||||||
.nbytesNames = static_cast<CARD16>(mode_name.size()),
|
.nbytesNames = static_cast<CARD16>(mode_name_bytes),
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
TRY(encode(client_info.output_buffer, crtc_id));
|
for (const auto& display : s_randr_displays)
|
||||||
|
TRY(encode(client_info.output_buffer, display.crtc_id));
|
||||||
|
|
||||||
TRY(encode(client_info.output_buffer, output_id));
|
for (const auto& display : s_randr_displays)
|
||||||
|
TRY(encode(client_info.output_buffer, display.output_id));
|
||||||
|
|
||||||
const CARD16 hsync_start = g_root.pixWidth;
|
for (const auto& display : s_randr_displays)
|
||||||
const CARD16 hsync_end = g_root.pixWidth + 1;
|
{
|
||||||
const CARD16 htotal = g_root.pixWidth + 1;
|
const CARD16 hsync_start = display.info.w;
|
||||||
|
const CARD16 hsync_end = display.info.w + 1;
|
||||||
|
const CARD16 htotal = display.info.w + 1;
|
||||||
|
|
||||||
const CARD16 vsync_start = g_root.pixHeight;
|
const CARD16 vsync_start = display.info.h;
|
||||||
const CARD16 vsync_end = g_root.pixHeight + 1;
|
const CARD16 vsync_end = display.info.h + 1;
|
||||||
const CARD16 vtotal = g_root.pixHeight + 1;
|
const CARD16 vtotal = display.info.h + 1;
|
||||||
|
|
||||||
const CARD32 clock = htotal * vtotal * 60;
|
const CARD32 clock = htotal * vtotal * 60;
|
||||||
|
|
||||||
xRRModeInfo mode_info {
|
xRRModeInfo mode_info {
|
||||||
.id = mode_id,
|
.id = display.mode_id,
|
||||||
.width = g_root.pixWidth,
|
.width = static_cast<CARD16>(display.info.w),
|
||||||
.height = g_root.pixHeight,
|
.height = static_cast<CARD16>(display.info.h),
|
||||||
.dotClock = clock,
|
.dotClock = clock,
|
||||||
.hSyncStart = hsync_start,
|
.hSyncStart = hsync_start,
|
||||||
.hSyncEnd = hsync_end,
|
.hSyncEnd = hsync_end,
|
||||||
.hTotal = htotal,
|
.hTotal = htotal,
|
||||||
.hSkew = 0,
|
.hSkew = 0,
|
||||||
.vSyncStart = vsync_start,
|
.vSyncStart = vsync_start,
|
||||||
.vSyncEnd = vsync_end,
|
.vSyncEnd = vsync_end,
|
||||||
.vTotal = vtotal,
|
.vTotal = vtotal,
|
||||||
.nameLength = static_cast<CARD16>(mode_name.size()),
|
.nameLength = static_cast<CARD16>(display.mode_str.size()),
|
||||||
.modeFlags = RR_HSyncPositive | RR_VSyncPositive,
|
.modeFlags = RR_HSyncPositive | RR_VSyncPositive,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, mode_info));
|
TRY(encode(client_info.output_buffer, mode_info));
|
||||||
|
}
|
||||||
|
|
||||||
TRY(encode(client_info.output_buffer, mode_name));
|
for (const auto& display : s_randr_displays)
|
||||||
for (size_t i = 0; (mode_name.size() + i) % 4; i++)
|
TRY(encode(client_info.output_buffer, display.mode_str));
|
||||||
TRY(encode(client_info.output_buffer, '\0'));
|
while (client_info.output_buffer.size() % 4)
|
||||||
|
TRY(encode<BYTE>(client_info.output_buffer, 0));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -175,27 +235,31 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" output: {}", request.output);
|
dprintln(" output: {}", request.output);
|
||||||
dprintln(" configTimestamp: {}", request.configTimestamp);
|
dprintln(" configTimestamp: {}", request.configTimestamp);
|
||||||
|
|
||||||
|
const auto& display = find_display_by_output(request.output);
|
||||||
|
|
||||||
xRRGetOutputInfoReply reply {
|
xRRGetOutputInfoReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 1 + 1 + 1 + 2,
|
.length = static_cast<CARD32>(1 + 1 + 1 + (display.output_str.size() + 3) / 4),
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.crtc = crtc_id,
|
.crtc = display.crtc_id,
|
||||||
.mmWidth = g_root.mmWidth,
|
.mmWidth = display.info.w * 254 / 960, // 96 DPI
|
||||||
.mmHeight = g_root.mmHeight,
|
.mmHeight = display.info.h * 254 / 960, // 96 DPI
|
||||||
.connection = RR_Connected,
|
.connection = RR_Connected,
|
||||||
.subpixelOrder = SubPixelUnknown,
|
.subpixelOrder = SubPixelUnknown,
|
||||||
.nCrtcs = 1,
|
.nCrtcs = 1,
|
||||||
.nModes = 1,
|
.nModes = 1,
|
||||||
.nPreferred = 1,
|
.nPreferred = 1,
|
||||||
.nClones = 0,
|
.nClones = 0,
|
||||||
.nameLength = 5,
|
.nameLength = static_cast<CARD16>(display.output_str.size()),
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
TRY(encode(client_info.output_buffer, crtc_id));
|
TRY(encode(client_info.output_buffer, display.crtc_id));
|
||||||
TRY(encode(client_info.output_buffer, mode_id));
|
TRY(encode(client_info.output_buffer, display.mode_id));
|
||||||
TRY(encode(client_info.output_buffer, "B-OUT\0\0\0"_sv));
|
TRY(encode(client_info.output_buffer, display.output_str));
|
||||||
|
while (client_info.output_buffer.size() % 4)
|
||||||
|
TRY(encode<BYTE>(client_info.output_buffer, 0));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -250,25 +314,27 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" crtc: {}", request.crtc);
|
dprintln(" crtc: {}", request.crtc);
|
||||||
dprintln(" configTimestamp: {}", request.configTimestamp);
|
dprintln(" configTimestamp: {}", request.configTimestamp);
|
||||||
|
|
||||||
|
const auto& display = find_display_by_crtc(request.crtc);
|
||||||
|
|
||||||
xRRGetCrtcInfoReply reply {
|
xRRGetCrtcInfoReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 2,
|
.length = 2,
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.x = 0,
|
.x = static_cast<INT16>(display.info.x),
|
||||||
.y = 0,
|
.y = static_cast<INT16>(display.info.y),
|
||||||
.width = g_root.pixWidth,
|
.width = static_cast<CARD16>(display.info.w),
|
||||||
.height = g_root.pixHeight,
|
.height = static_cast<CARD16>(display.info.h),
|
||||||
.mode = mode_id,
|
.mode = display.mode_id,
|
||||||
.rotation = RR_Rotate_0,
|
.rotation = RR_Rotate_0,
|
||||||
.rotations = RR_Rotate_0,
|
.rotations = RR_Rotate_0,
|
||||||
.nOutput = 1,
|
.nOutput = 1,
|
||||||
.nPossibleOutput = 1,
|
.nPossibleOutput = 1,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
TRY(encode(client_info.output_buffer, output_id));
|
TRY(encode(client_info.output_buffer, display.output_id));
|
||||||
TRY(encode(client_info.output_buffer, output_id));
|
TRY(encode(client_info.output_buffer, display.output_id));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -285,13 +351,13 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" mode: {}", request.mode);
|
dprintln(" mode: {}", request.mode);
|
||||||
dprintln(" rotation: {}", request.rotation);
|
dprintln(" rotation: {}", request.rotation);
|
||||||
|
|
||||||
timestamp = time(nullptr);
|
s_timestamp = time(nullptr);
|
||||||
xRRSetCrtcConfigReply reply {
|
xRRSetCrtcConfigReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 0,
|
.length = 0,
|
||||||
.newTimestamp = timestamp,
|
.newTimestamp = s_timestamp,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -301,15 +367,15 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
{
|
{
|
||||||
auto request = decode<xRRGetCrtcGammaSizeReq>(packet).value();
|
auto request = decode<xRRGetCrtcGammaSizeReq>(packet).value();
|
||||||
|
|
||||||
dprintln("RRGetCrtcGammaSize");
|
dwarnln("RRGetCrtcGammaSize");
|
||||||
dprintln(" crtc: {}", request.crtc);
|
dwarnln(" crtc: {}", request.crtc);
|
||||||
|
|
||||||
xRRGetCrtcGammaSizeReply reply {
|
xRRGetCrtcGammaSizeReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 0,
|
.length = 0,
|
||||||
.size = 1,
|
.size = 256,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -323,17 +389,16 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" crtc: {}", request.crtc);
|
dprintln(" crtc: {}", request.crtc);
|
||||||
|
|
||||||
xRRGetCrtcGammaReply reply {
|
xRRGetCrtcGammaReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 2,
|
.length = (6 * 256) / 4,
|
||||||
.size = 1,
|
.size = 256,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
TRY(encode<CARD16>(client_info.output_buffer, 1));
|
for (size_t i = 0; i < 3; i++)
|
||||||
TRY(encode<CARD16>(client_info.output_buffer, 1));
|
for (size_t j = 0; j < 256; j++)
|
||||||
TRY(encode<CARD16>(client_info.output_buffer, 1));
|
TRY(encode<CARD16>(client_info.output_buffer, j * 65535 / 255));
|
||||||
TRY(encode<CARD16>(client_info.output_buffer, 0));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -345,17 +410,17 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" crtc: {}", request.crtc);
|
dprintln(" crtc: {}", request.crtc);
|
||||||
|
|
||||||
xRRGetCrtcTransformReply reply {
|
xRRGetCrtcTransformReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 16,
|
.length = 16,
|
||||||
.pendingTransform = transform,
|
.pendingTransform = transform,
|
||||||
.hasTransforms = xFalse,
|
.hasTransforms = xFalse,
|
||||||
.currentTransform = transform,
|
.currentTransform = transform,
|
||||||
.pendingNbytesFilter = 0,
|
.pendingNbytesFilter = 0,
|
||||||
.pendingNparamsFilter = 0,
|
.pendingNparamsFilter = 0,
|
||||||
.currentNbytesFilter = 0,
|
.currentNbytesFilter = 0,
|
||||||
.currentNparamsFilter = 0,
|
.currentNparamsFilter = 0,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -369,23 +434,23 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" crtc: {}", request.crtc);
|
dprintln(" crtc: {}", request.crtc);
|
||||||
|
|
||||||
xRRGetPanningReply reply {
|
xRRGetPanningReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 1,
|
.length = 1,
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.left = 0,
|
.left = 0,
|
||||||
.top = 0,
|
.top = 0,
|
||||||
.width = 0,
|
.width = 0,
|
||||||
.height = 0,
|
.height = 0,
|
||||||
.track_left = 0,
|
.track_left = 0,
|
||||||
.track_top = 0,
|
.track_top = 0,
|
||||||
.track_width = 0,
|
.track_width = 0,
|
||||||
.track_height = 0,
|
.track_height = 0,
|
||||||
.border_left = 0,
|
.border_left = 0,
|
||||||
.border_top = 0,
|
.border_top = 0,
|
||||||
.border_right = 0,
|
.border_right = 0,
|
||||||
.border_bottom = 0,
|
.border_bottom = 0,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -399,10 +464,10 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {}", request.window);
|
||||||
|
|
||||||
xRRGetOutputPrimaryReply reply {
|
xRRGetOutputPrimaryReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 0,
|
.length = 0,
|
||||||
.output = output_id,
|
.output = s_randr_displays.front().output_id,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
@@ -416,10 +481,10 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" window: {}", request.window);
|
dprintln(" window: {}", request.window);
|
||||||
|
|
||||||
xRRGetProvidersReply reply {
|
xRRGetProvidersReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 0,
|
.length = 0,
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.nProviders = 0,
|
.nProviders = 0,
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
@@ -435,31 +500,33 @@ static BAN::ErrorOr<void> extension_randr(Client& client_info, BAN::ConstByteSpa
|
|||||||
dprintln(" get_active: {}", request.get_active);
|
dprintln(" get_active: {}", request.get_active);
|
||||||
|
|
||||||
xRRGetMonitorsReply reply {
|
xRRGetMonitorsReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.status = Success,
|
.status = Success,
|
||||||
.sequenceNumber = client_info.sequence,
|
.sequenceNumber = client_info.sequence,
|
||||||
.length = 6 + 1,
|
.length = static_cast<CARD32>(6 * s_randr_displays.size() + s_randr_displays.size()),
|
||||||
.timestamp = timestamp,
|
.timestamp = s_timestamp,
|
||||||
.nmonitors = 1,
|
.nmonitors = static_cast<CARD32>(s_randr_displays.size()),
|
||||||
.noutputs = 1,
|
.noutputs = static_cast<CARD32>(s_randr_displays.size()),
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
xRRMonitorInfo monitor {
|
for (const auto& display : s_randr_displays)
|
||||||
.name = None,
|
{
|
||||||
.primary = xTrue,
|
xRRMonitorInfo monitor {
|
||||||
.automatic = xTrue,
|
.name = display.name_atom,
|
||||||
.noutput = 1,
|
.primary = (&display == &s_randr_displays.front()),
|
||||||
.x = 0,
|
.automatic = xTrue,
|
||||||
.y = 0,
|
.noutput = 1,
|
||||||
.width = g_root.pixWidth,
|
.x = static_cast<INT16>(display.info.x),
|
||||||
.height = g_root.pixHeight,
|
.y = static_cast<INT16>(display.info.y),
|
||||||
.widthInMillimeters = g_root.mmWidth,
|
.width = static_cast<CARD16>(display.info.w),
|
||||||
.heightInMillimeters = g_root.mmHeight,
|
.height = static_cast<CARD16>(display.info.h),
|
||||||
};
|
.widthInMillimeters = display.info.w * 254 / 96, // 96 DPI
|
||||||
TRY(encode(client_info.output_buffer, monitor));
|
.heightInMillimeters = display.info.h * 254 / 96, // 96 DPI
|
||||||
|
};
|
||||||
TRY(encode(client_info.output_buffer, output_id));
|
TRY(encode(client_info.output_buffer, monitor));
|
||||||
|
TRY(encode(client_info.output_buffer, display.output_id));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
119
xbanan/ExtXRes.cpp
Normal file
119
xbanan/ExtXRes.cpp
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include "Extensions.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include <X11/X.h>
|
||||||
|
#include <X11/extensions/XResproto.h>
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
static BAN::ErrorOr<void> for_each_client(uint32_t target_spec, const F& callback)
|
||||||
|
{
|
||||||
|
for (const auto& [fd, thingy] : g_epoll_thingies)
|
||||||
|
{
|
||||||
|
if (thingy.type != EpollThingy::Type::Client)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto& client_info = thingy.value.get<Client>();
|
||||||
|
if (target_spec && (target_spec >> 20) != client_info.fd)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
TRY(callback(client_info, target_spec ? target_spec : (client_info.fd << 20)));
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<void> extension_xres(Client& client_info, BAN::ConstByteSpan packet)
|
||||||
|
{
|
||||||
|
const uint8_t major_opcode = packet[0];
|
||||||
|
const uint8_t minor_opcode = packet[1];
|
||||||
|
|
||||||
|
switch (minor_opcode)
|
||||||
|
{
|
||||||
|
case X_XResQueryVersion:
|
||||||
|
{
|
||||||
|
auto request = decode<xXResQueryVersionReq>(packet).value();
|
||||||
|
|
||||||
|
dprintln("XResQueryVersion");
|
||||||
|
dprintln(" clientMajor: {}", request.client_major);
|
||||||
|
dprintln(" clientMinor: {}", request.client_minor);
|
||||||
|
|
||||||
|
xXResQueryVersionReply reply {
|
||||||
|
.type = X_Reply,
|
||||||
|
.sequenceNumber = client_info.sequence,
|
||||||
|
.length = 0,
|
||||||
|
.server_major = 1,
|
||||||
|
.server_minor = 2,
|
||||||
|
};
|
||||||
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case X_XResQueryClientIds:
|
||||||
|
{
|
||||||
|
auto request = decode<xXResQueryClientIdsReq>(packet).value();
|
||||||
|
|
||||||
|
dprintln("XResQueryClientIds");
|
||||||
|
dprintln(" numSpecs: {}", request.numSpecs);
|
||||||
|
|
||||||
|
uint32_t num_ids { 0 };
|
||||||
|
BAN::Vector<uint8_t> query_result;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < request.numSpecs; i++)
|
||||||
|
{
|
||||||
|
auto spec = decode<xXResClientIdSpec>(packet).value();
|
||||||
|
|
||||||
|
TRY(for_each_client(spec.client, [&](const Client& client_info, uint32_t client_spec) -> BAN::ErrorOr<void> {
|
||||||
|
if (spec.mask == None || (spec.mask & X_XResClientXIDMask))
|
||||||
|
{
|
||||||
|
xXResClientIdValue value {
|
||||||
|
.spec = {
|
||||||
|
.client = client_spec,
|
||||||
|
.mask = X_XResClientXIDMask,
|
||||||
|
},
|
||||||
|
.length = 0,
|
||||||
|
};
|
||||||
|
TRY(encode(query_result, value));
|
||||||
|
num_ids++;
|
||||||
|
}
|
||||||
|
if ((spec.mask == None || (spec.mask & X_XResLocalClientPIDMask)) && client_info.pid.has_value())
|
||||||
|
{
|
||||||
|
xXResClientIdValue value {
|
||||||
|
.spec = {
|
||||||
|
.client = client_spec,
|
||||||
|
.mask = X_XResLocalClientPIDMask,
|
||||||
|
},
|
||||||
|
.length = 4,
|
||||||
|
};
|
||||||
|
TRY(encode(query_result, value));
|
||||||
|
TRY(encode(query_result, client_info.pid.value()));
|
||||||
|
num_ids++;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
xXResQueryClientIdsReply reply {
|
||||||
|
.type = X_Reply,
|
||||||
|
.sequenceNumber = client_info.sequence,
|
||||||
|
.length = static_cast<uint32_t>(query_result.size() / 4),
|
||||||
|
.numIds = num_ids,
|
||||||
|
};
|
||||||
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
TRY(encode(client_info.output_buffer, query_result));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
dwarnln("unsupported opcode XRes minor opcode {}", minor_opcode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct XResInstaller
|
||||||
|
{
|
||||||
|
XResInstaller()
|
||||||
|
{
|
||||||
|
install_extension(XRES_NAME, 6, 0, extension_xres);
|
||||||
|
}
|
||||||
|
} installer;
|
||||||
@@ -385,7 +385,7 @@ static BAN::ErrorOr<BAN::RefPtr<PCFFont>> parse_font(const BAN::String& path)
|
|||||||
font->font_ascent = font->max_bounds.ascent;
|
font->font_ascent = font->max_bounds.ascent;
|
||||||
font->font_descent = font->max_bounds.descent;
|
font->font_descent = font->max_bounds.descent;
|
||||||
|
|
||||||
font->is_cursor_font = (path == "fonts/misc/cursor.pcf.gz"_sv);
|
font->is_cursor_font = (path == FONT_PATH "/misc/cursor.pcf.gz"_sv);
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
@@ -393,7 +393,7 @@ static BAN::ErrorOr<BAN::RefPtr<PCFFont>> parse_font(const BAN::String& path)
|
|||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
static void initialize_fonts()
|
static void initialize_fonts()
|
||||||
{
|
{
|
||||||
const char* font_path = "fonts/misc";
|
const char* font_path = FONT_PATH "/misc";
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,349 +1,5 @@
|
|||||||
#include "Keymap.h"
|
#include "Keymap.h"
|
||||||
|
|
||||||
#include <BAN/StringView.h>
|
uint32_t g_keymap[g_keymap_size][g_keymap_layers] {};
|
||||||
|
uint8_t g_modifier_map[8][2] {};
|
||||||
#include <LibInput/KeyboardLayout.h>
|
|
||||||
|
|
||||||
#include <X11/X.h>
|
|
||||||
#include <X11/keysym.h>
|
|
||||||
#include <X11/XF86keysym.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#undef None
|
|
||||||
|
|
||||||
uint32_t g_keymap[0x100][g_keymap_layers];
|
|
||||||
|
|
||||||
uint8_t g_pressed_keys[32] {};
|
uint8_t g_pressed_keys[32] {};
|
||||||
|
|
||||||
static constexpr uint32_t my_key_to_x_keysym(LibInput::Key key)
|
|
||||||
{
|
|
||||||
using LibInput::Key;
|
|
||||||
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case Key::A:
|
|
||||||
return XK_A;
|
|
||||||
case Key::B:
|
|
||||||
return XK_B;
|
|
||||||
case Key::C:
|
|
||||||
return XK_C;
|
|
||||||
case Key::D:
|
|
||||||
return XK_D;
|
|
||||||
case Key::E:
|
|
||||||
return XK_E;
|
|
||||||
case Key::F:
|
|
||||||
return XK_F;
|
|
||||||
case Key::G:
|
|
||||||
return XK_G;
|
|
||||||
case Key::H:
|
|
||||||
return XK_H;
|
|
||||||
case Key::I:
|
|
||||||
return XK_I;
|
|
||||||
case Key::J:
|
|
||||||
return XK_J;
|
|
||||||
case Key::K:
|
|
||||||
return XK_K;
|
|
||||||
case Key::L:
|
|
||||||
return XK_L;
|
|
||||||
case Key::M:
|
|
||||||
return XK_M;
|
|
||||||
case Key::N:
|
|
||||||
return XK_N;
|
|
||||||
case Key::O:
|
|
||||||
return XK_O;
|
|
||||||
case Key::P:
|
|
||||||
return XK_P;
|
|
||||||
case Key::Q:
|
|
||||||
return XK_Q;
|
|
||||||
case Key::R:
|
|
||||||
return XK_R;
|
|
||||||
case Key::S:
|
|
||||||
return XK_S;
|
|
||||||
case Key::T:
|
|
||||||
return XK_T;
|
|
||||||
case Key::U:
|
|
||||||
return XK_U;
|
|
||||||
case Key::V:
|
|
||||||
return XK_V;
|
|
||||||
case Key::W:
|
|
||||||
return XK_W;
|
|
||||||
case Key::X:
|
|
||||||
return XK_X;
|
|
||||||
case Key::Y:
|
|
||||||
return XK_Y;
|
|
||||||
case Key::Z:
|
|
||||||
return XK_Z;
|
|
||||||
case Key::A_Ring:
|
|
||||||
return XK_Aring;
|
|
||||||
case Key::A_Umlaut:
|
|
||||||
return XK_Adiaeresis;
|
|
||||||
case Key::O_Umlaut:
|
|
||||||
return XK_Odiaeresis;
|
|
||||||
case Key::_0:
|
|
||||||
return XK_0;
|
|
||||||
case Key::_1:
|
|
||||||
return XK_1;
|
|
||||||
case Key::_2:
|
|
||||||
return XK_2;
|
|
||||||
case Key::_3:
|
|
||||||
return XK_3;
|
|
||||||
case Key::_4:
|
|
||||||
return XK_4;
|
|
||||||
case Key::_5:
|
|
||||||
return XK_5;
|
|
||||||
case Key::_6:
|
|
||||||
return XK_6;
|
|
||||||
case Key::_7:
|
|
||||||
return XK_7;
|
|
||||||
case Key::_8:
|
|
||||||
return XK_8;
|
|
||||||
case Key::_9:
|
|
||||||
return XK_9;
|
|
||||||
case Key::F1:
|
|
||||||
return XK_F1;
|
|
||||||
case Key::F2:
|
|
||||||
return XK_F2;
|
|
||||||
case Key::F3:
|
|
||||||
return XK_F3;
|
|
||||||
case Key::F4:
|
|
||||||
return XK_F4;
|
|
||||||
case Key::F5:
|
|
||||||
return XK_F5;
|
|
||||||
case Key::F6:
|
|
||||||
return XK_F6;
|
|
||||||
case Key::F7:
|
|
||||||
return XK_F7;
|
|
||||||
case Key::F8:
|
|
||||||
return XK_F8;
|
|
||||||
case Key::F9:
|
|
||||||
return XK_F9;
|
|
||||||
case Key::F10:
|
|
||||||
return XK_F10;
|
|
||||||
case Key::F11:
|
|
||||||
return XK_F11;
|
|
||||||
case Key::F12:
|
|
||||||
return XK_F12;
|
|
||||||
case Key::Insert:
|
|
||||||
return XK_Insert;
|
|
||||||
case Key::PrintScreen:
|
|
||||||
return XK_Print;
|
|
||||||
case Key::Delete:
|
|
||||||
return XK_Delete;
|
|
||||||
case Key::Home:
|
|
||||||
return XK_Home;
|
|
||||||
case Key::End:
|
|
||||||
return XK_End;
|
|
||||||
case Key::PageUp:
|
|
||||||
return XK_Page_Up;
|
|
||||||
case Key::PageDown:
|
|
||||||
return XK_Page_Down;
|
|
||||||
case Key::Enter:
|
|
||||||
return XK_Return;
|
|
||||||
case Key::Space:
|
|
||||||
return XK_space;
|
|
||||||
case Key::ExclamationMark:
|
|
||||||
return XK_exclam;
|
|
||||||
case Key::DoubleQuote:
|
|
||||||
return XK_quotedbl;
|
|
||||||
case Key::Hashtag:
|
|
||||||
return XK_numbersign;
|
|
||||||
case Key::Currency:
|
|
||||||
return XK_currency;
|
|
||||||
case Key::Percent:
|
|
||||||
return XK_percent;
|
|
||||||
case Key::Ampersand:
|
|
||||||
return XK_ampersand;
|
|
||||||
case Key::Slash:
|
|
||||||
return XK_slash;
|
|
||||||
case Key::Section:
|
|
||||||
return XK_section;
|
|
||||||
case Key::Half:
|
|
||||||
return XK_onehalf;
|
|
||||||
case Key::OpenParenthesis:
|
|
||||||
return '(';
|
|
||||||
case Key::CloseParenthesis:
|
|
||||||
return ')';
|
|
||||||
case Key::OpenSquareBracket:
|
|
||||||
return '[';
|
|
||||||
case Key::CloseSquareBracket:
|
|
||||||
return ']';
|
|
||||||
case Key::OpenCurlyBracket:
|
|
||||||
return '{';
|
|
||||||
case Key::CloseCurlyBracket:
|
|
||||||
return '}';
|
|
||||||
case Key::Equals:
|
|
||||||
return '=';
|
|
||||||
case Key::QuestionMark:
|
|
||||||
return '?';
|
|
||||||
case Key::Plus:
|
|
||||||
return '+';
|
|
||||||
case Key::BackSlash:
|
|
||||||
return '\\';
|
|
||||||
case Key::Acute:
|
|
||||||
return XK_acute;
|
|
||||||
case Key::BackTick:
|
|
||||||
return '`';
|
|
||||||
case Key::TwoDots:
|
|
||||||
return XK_diaeresis;
|
|
||||||
case Key::Cedilla:
|
|
||||||
return XK_Ccedilla;
|
|
||||||
case Key::Backspace:
|
|
||||||
return XK_BackSpace;
|
|
||||||
case Key::AtSign:
|
|
||||||
return XK_at;
|
|
||||||
case Key::Pound:
|
|
||||||
return XK_sterling;
|
|
||||||
case Key::Dollar:
|
|
||||||
return XK_dollar;
|
|
||||||
case Key::Euro:
|
|
||||||
return XK_EuroSign;
|
|
||||||
case Key::Escape:
|
|
||||||
return XK_Escape;
|
|
||||||
case Key::Tab:
|
|
||||||
return XK_Tab;
|
|
||||||
case Key::CapsLock:
|
|
||||||
return XK_Caps_Lock;
|
|
||||||
case Key::LeftShift:
|
|
||||||
return XK_Shift_L;
|
|
||||||
case Key::LeftCtrl:
|
|
||||||
return XK_Control_L;
|
|
||||||
case Key::Super:
|
|
||||||
return XK_Super_L;
|
|
||||||
case Key::LeftAlt:
|
|
||||||
return XK_Alt_L;
|
|
||||||
case Key::RightAlt:
|
|
||||||
return XK_Alt_R;
|
|
||||||
case Key::RightCtrl:
|
|
||||||
return XK_Control_R;
|
|
||||||
case Key::RightShift:
|
|
||||||
return XK_Shift_R;
|
|
||||||
case Key::SingleQuote:
|
|
||||||
return '\'';
|
|
||||||
case Key::Asterix:
|
|
||||||
return '*';
|
|
||||||
case Key::Caret:
|
|
||||||
return '^';
|
|
||||||
case Key::Tilde:
|
|
||||||
return '~';
|
|
||||||
case Key::ArrowUp:
|
|
||||||
return XK_Up;
|
|
||||||
case Key::ArrowDown:
|
|
||||||
return XK_Down;
|
|
||||||
case Key::ArrowLeft:
|
|
||||||
return XK_Left;
|
|
||||||
case Key::ArrowRight:
|
|
||||||
return XK_Right;
|
|
||||||
case Key::Comma:
|
|
||||||
return ',';
|
|
||||||
case Key::Semicolon:
|
|
||||||
return ';';
|
|
||||||
case Key::Period:
|
|
||||||
return '.';
|
|
||||||
case Key::Colon:
|
|
||||||
return ':';
|
|
||||||
case Key::Hyphen:
|
|
||||||
return '-';
|
|
||||||
case Key::Underscore:
|
|
||||||
return '_';
|
|
||||||
case Key::NumLock:
|
|
||||||
return XK_Num_Lock;
|
|
||||||
case Key::ScrollLock:
|
|
||||||
return XK_Scroll_Lock;
|
|
||||||
case Key::LessThan:
|
|
||||||
return '<';
|
|
||||||
case Key::GreaterThan:
|
|
||||||
return '>';
|
|
||||||
case Key::Pipe:
|
|
||||||
return '|';
|
|
||||||
case Key::Negation:
|
|
||||||
return XK_notsign;
|
|
||||||
case Key::BrokenBar:
|
|
||||||
return XK_brokenbar;
|
|
||||||
case Key::Numpad0:
|
|
||||||
return XK_KP_0;
|
|
||||||
case Key::Numpad1:
|
|
||||||
return XK_KP_1;
|
|
||||||
case Key::Numpad2:
|
|
||||||
return XK_KP_2;
|
|
||||||
case Key::Numpad3:
|
|
||||||
return XK_KP_3;
|
|
||||||
case Key::Numpad4:
|
|
||||||
return XK_KP_4;
|
|
||||||
case Key::Numpad5:
|
|
||||||
return XK_KP_5;
|
|
||||||
case Key::Numpad6:
|
|
||||||
return XK_KP_6;
|
|
||||||
case Key::Numpad7:
|
|
||||||
return XK_KP_7;
|
|
||||||
case Key::Numpad8:
|
|
||||||
return XK_KP_8;
|
|
||||||
case Key::Numpad9:
|
|
||||||
return XK_KP_9;
|
|
||||||
case Key::NumpadPlus:
|
|
||||||
return XK_KP_Add;
|
|
||||||
case Key::NumpadMinus:
|
|
||||||
return XK_KP_Subtract;
|
|
||||||
case Key::NumpadMultiply:
|
|
||||||
return XK_KP_Multiply;
|
|
||||||
case Key::NumpadDivide:
|
|
||||||
return XK_KP_Divide;
|
|
||||||
case Key::NumpadEnter:
|
|
||||||
return XK_KP_Enter;
|
|
||||||
case Key::NumpadDecimal:
|
|
||||||
return XK_KP_Decimal;
|
|
||||||
case Key::VolumeMute:
|
|
||||||
return XF86XK_AudioMute;
|
|
||||||
case Key::VolumeUp:
|
|
||||||
return XF86XK_AudioRaiseVolume;
|
|
||||||
case Key::VolumeDown:
|
|
||||||
return XF86XK_AudioLowerVolume;
|
|
||||||
case Key::Calculator:
|
|
||||||
return XF86XK_Calculator;
|
|
||||||
case Key::MediaPlayPause:
|
|
||||||
return XF86XK_AudioPlay;
|
|
||||||
case Key::MediaStop:
|
|
||||||
return XF86XK_AudioStop;
|
|
||||||
case Key::MediaPrevious:
|
|
||||||
return XF86XK_AudioPrev;
|
|
||||||
case Key::MediaNext:
|
|
||||||
return XF86XK_AudioNext;
|
|
||||||
|
|
||||||
case Key::Invalid:
|
|
||||||
case Key::None:
|
|
||||||
case Key::Count:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NoSymbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
BAN::ErrorOr<void> initialize_keymap()
|
|
||||||
{
|
|
||||||
for (auto& keycode : g_keymap)
|
|
||||||
for (auto& keysym : keycode)
|
|
||||||
keysym = NoSymbol;
|
|
||||||
|
|
||||||
// FIXME: get this from somewhere (gui command? enviroment? tmp file?)
|
|
||||||
const auto keymap_path = "./us.keymap"_sv;
|
|
||||||
|
|
||||||
TRY(LibInput::KeyboardLayout::initialize());
|
|
||||||
|
|
||||||
auto& keyboard_layout = LibInput::KeyboardLayout::get();
|
|
||||||
TRY(keyboard_layout.load_from_file(keymap_path));
|
|
||||||
|
|
||||||
const BAN::Span<const LibInput::Key> my_keymaps[] {
|
|
||||||
keyboard_layout.keymap_normal(),
|
|
||||||
keyboard_layout.keymap_shift(),
|
|
||||||
keyboard_layout.keymap_altgr(),
|
|
||||||
keyboard_layout.keymap_altgr(), // add shift+altgr map?
|
|
||||||
};
|
|
||||||
|
|
||||||
for (size_t keycode = g_keymap_min_keycode; keycode < g_keymap_max_keycode; keycode++)
|
|
||||||
for (size_t layer = 0; layer < g_keymap_layers; layer++)
|
|
||||||
if (auto my_key = my_keymaps[layer][keycode - g_keymap_min_keycode]; my_key != LibInput::Key::None)
|
|
||||||
if (auto keysym = my_key_to_x_keysym(my_key); keysym != NoSymbol)
|
|
||||||
g_keymap[keycode][layer] = (layer % 2) ? toupper(keysym) : tolower(keysym);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Errors.h>
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
BAN::ErrorOr<void> initialize_keymap();
|
|
||||||
|
|
||||||
constexpr size_t g_keymap_min_keycode = 8;
|
constexpr size_t g_keymap_min_keycode = 8;
|
||||||
constexpr size_t g_keymap_max_keycode = 255;
|
constexpr size_t g_keymap_max_keycode = 255;
|
||||||
|
constexpr size_t g_keymap_size = g_keymap_max_keycode - g_keymap_min_keycode + 1;
|
||||||
|
|
||||||
constexpr size_t g_keymap_layers = 4;
|
constexpr size_t g_keymap_layers = 4;
|
||||||
extern uint32_t g_keymap[0x100][g_keymap_layers];
|
extern uint32_t g_keymap[g_keymap_size][g_keymap_layers];
|
||||||
|
|
||||||
|
// shift, capslock, control, alt, numlock, level5 shift, super, altgr with 2 keycodes per modifier
|
||||||
|
constexpr size_t g_modifier_layers = 2;
|
||||||
|
extern uint8_t g_modifier_map[8][g_modifier_layers];
|
||||||
|
|
||||||
extern uint8_t g_pressed_keys[32];
|
extern uint8_t g_pressed_keys[32];
|
||||||
|
|||||||
@@ -42,17 +42,23 @@ enum class SystemCursorType
|
|||||||
ResizeHorizontal,
|
ResizeHorizontal,
|
||||||
};
|
};
|
||||||
|
|
||||||
// initialize, poll_events, create_window and invalidate are required
|
// initialize, create_window and invalidate are required
|
||||||
|
// poll_events is required when an event fd is registered
|
||||||
struct PlatformOps
|
struct PlatformOps
|
||||||
{
|
{
|
||||||
/* Do platform initialization */
|
/* Do platform initialization */
|
||||||
bool (*initialize)(uint32_t* width, uint32_t* height);
|
bool (*initialize)();
|
||||||
/* Handle pending events */
|
/* Handle pending events */
|
||||||
void (*poll_events)(void*);
|
void (*poll_events)(void*);
|
||||||
/* Create a window with given size */
|
/* Create a window with given size */
|
||||||
BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> (*create_window)(PlatformWindow* parent, WindowType, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height);
|
BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> (*create_window)(WindowType, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||||
/* Invaldate part of a window */
|
/* All invalidate calls during one frame happen between calls to begin_frame and end_frame. pixels is in ARGB8888
|
||||||
void (*invalidate)(PlatformWindow*, const uint32_t* pixels, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
* invalidate should update the underlying textures
|
||||||
|
* begin_frame should do any necessary preparations to update a frame
|
||||||
|
* end_frame should flush the updated texturee to the window */
|
||||||
|
void (*invalidate)(PlatformWindow*, const void* pixels, uint32_t pitch, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
||||||
|
void (*begin_frame)(PlatformWindow*);
|
||||||
|
void (*end_frame)(PlatformWindow*);
|
||||||
/* Request resize of a window, can be async */
|
/* Request resize of a window, can be async */
|
||||||
void (*request_resize)(PlatformWindow*, uint32_t width, uint32_t height);
|
void (*request_resize)(PlatformWindow*, uint32_t width, uint32_t height);
|
||||||
/* Request window repositioning */
|
/* Request window repositioning */
|
||||||
@@ -73,3 +79,5 @@ struct PlatformOps
|
|||||||
void (*set_cursor)(PlatformWindow*, PlatformCursor*);
|
void (*set_cursor)(PlatformWindow*, PlatformCursor*);
|
||||||
};
|
};
|
||||||
extern PlatformOps g_platform_ops;
|
extern PlatformOps g_platform_ops;
|
||||||
|
|
||||||
|
void register_display(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "../Events.h"
|
#include "../Events.h"
|
||||||
|
#include "../Keymap.h"
|
||||||
#include "../Platform.h"
|
#include "../Platform.h"
|
||||||
|
|
||||||
#include <BAN/Atomic.h>
|
#include <BAN/Atomic.h>
|
||||||
@@ -52,13 +53,6 @@ struct SDLCursor final : public PlatformCursor
|
|||||||
|
|
||||||
static int s_eventfd { -1 };
|
static int s_eventfd { -1 };
|
||||||
|
|
||||||
struct Keymap
|
|
||||||
{
|
|
||||||
consteval Keymap();
|
|
||||||
uint8_t map[SDL_SCANCODE_COUNT];
|
|
||||||
};
|
|
||||||
static Keymap s_sdl_keymap;
|
|
||||||
|
|
||||||
static SDL_Cursor* s_default_cursor { nullptr };
|
static SDL_Cursor* s_default_cursor { nullptr };
|
||||||
|
|
||||||
static void* sdl3_thread(void*)
|
static void* sdl3_thread(void*)
|
||||||
@@ -73,7 +67,9 @@ static void* sdl3_thread(void*)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sdl3_initialize(uint32_t* display_w, uint32_t* display_h)
|
static void sdl3_initialize_keymap();
|
||||||
|
|
||||||
|
static bool sdl3_initialize()
|
||||||
{
|
{
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
|
||||||
{
|
{
|
||||||
@@ -81,17 +77,20 @@ static bool sdl3_initialize(uint32_t* display_w, uint32_t* display_h)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*display_w = *display_h = 0;
|
|
||||||
|
|
||||||
const SDL_DisplayID* display_ids = SDL_GetDisplays(nullptr);
|
const SDL_DisplayID* display_ids = SDL_GetDisplays(nullptr);
|
||||||
for (int i = 0; display_ids[i]; i++)
|
for (int i = 0; display_ids[i]; i++)
|
||||||
{
|
{
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
SDL_GetDisplayBounds(display_ids[i], &rect);
|
if (!SDL_GetDisplayBounds(display_ids[i], &rect))
|
||||||
*display_w = BAN::Math::max<uint32_t>(*display_w, rect.x + rect.w);
|
{
|
||||||
*display_h = BAN::Math::max<uint32_t>(*display_h, rect.y + rect.h);
|
dwarnln("Could not display {} bounds: {}", SDL_GetError());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
register_display(rect.x, rect.y, rect.w, rect.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdl3_initialize_keymap();
|
||||||
|
|
||||||
s_default_cursor = SDL_GetCursor();
|
s_default_cursor = SDL_GetCursor();
|
||||||
|
|
||||||
s_eventfd = eventfd(0, 0);
|
s_eventfd = eventfd(0, 0);
|
||||||
@@ -109,7 +108,7 @@ static bool sdl3_initialize(uint32_t* display_w, uint32_t* display_h)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> sdl3_create_window(PlatformWindow* parent, WindowType type, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height)
|
static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> sdl3_create_window(WindowType type, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
auto window = TRY(BAN::UniqPtr<SDLWindow>::create());
|
auto window = TRY(BAN::UniqPtr<SDLWindow>::create());
|
||||||
|
|
||||||
@@ -121,29 +120,19 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> sdl3_create_window(PlatformWin
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case WindowType::Normal:
|
case WindowType::Normal:
|
||||||
case WindowType::Utility:
|
|
||||||
flags = SDL_WINDOW_RESIZABLE;
|
flags = SDL_WINDOW_RESIZABLE;
|
||||||
break;
|
break;
|
||||||
|
case WindowType::Utility:
|
||||||
|
flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_UTILITY;
|
||||||
|
break;
|
||||||
case WindowType::Popup:
|
case WindowType::Popup:
|
||||||
flags = SDL_WINDOW_BORDERLESS;
|
flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_UTILITY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent == nullptr || type != WindowType::Popup)
|
flags |= SDL_WINDOW_TRANSPARENT;
|
||||||
{
|
|
||||||
if (type != WindowType::Normal)
|
|
||||||
flags |= SDL_WINDOW_UTILITY;
|
|
||||||
window->window = SDL_CreateWindow("", width, height, flags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto& sdl_parent = *static_cast<SDLWindow*>(parent);
|
|
||||||
|
|
||||||
int parent_x, parent_y;
|
window->window = SDL_CreateWindow("", width, height, flags);
|
||||||
SDL_GetWindowPosition(sdl_parent.window, &parent_x, &parent_y);
|
|
||||||
|
|
||||||
window->window = SDL_CreatePopupWindow(sdl_parent.window, x - parent_x, y - parent_y, width, height, flags | SDL_WINDOW_POPUP_MENU);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window->window == nullptr)
|
if (window->window == nullptr)
|
||||||
{
|
{
|
||||||
@@ -151,6 +140,9 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> sdl3_create_window(PlatformWin
|
|||||||
return BAN::Error::from_errno(EFAULT);
|
return BAN::Error::from_errno(EFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (x != 0 || y != 0)
|
||||||
|
SDL_SetWindowPosition(window->window, x, y);
|
||||||
|
|
||||||
window->renderer = SDL_CreateRenderer(window->window, nullptr);
|
window->renderer = SDL_CreateRenderer(window->window, nullptr);
|
||||||
if (window->renderer == nullptr)
|
if (window->renderer == nullptr)
|
||||||
{
|
{
|
||||||
@@ -158,6 +150,8 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> sdl3_create_window(PlatformWin
|
|||||||
return BAN::Error::from_errno(EFAULT);
|
return BAN::Error::from_errno(EFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(window->renderer, 0, 0, 0, 0);
|
||||||
|
|
||||||
window->texture = SDL_CreateTexture(window->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
window->texture = SDL_CreateTexture(window->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||||
if (window->texture == nullptr)
|
if (window->texture == nullptr)
|
||||||
{
|
{
|
||||||
@@ -270,28 +264,30 @@ static void sdl3_poll_events(void*)
|
|||||||
case SDL_EVENT_KEY_UP:
|
case SDL_EVENT_KEY_UP:
|
||||||
case SDL_EVENT_KEY_DOWN:
|
case SDL_EVENT_KEY_DOWN:
|
||||||
{
|
{
|
||||||
uint8_t scancode = s_sdl_keymap.map[event.key.scancode];
|
const uint8_t xmod =
|
||||||
|
((event.key.mod & SDL_KMOD_SHIFT) ? (1 << 0) : 0) |
|
||||||
uint8_t xmod { 0 };
|
((event.key.mod & SDL_KMOD_CAPS) ? (1 << 1) : 0) |
|
||||||
if (event.key.mod & SDL_KMOD_SHIFT)
|
((event.key.mod & SDL_KMOD_CTRL) ? (1 << 2) : 0) |
|
||||||
xmod |= (1 << 0);
|
((event.key.mod & SDL_KMOD_ALT) ? (1 << 3) : 0) |
|
||||||
if (event.key.mod & SDL_KMOD_CAPS)
|
((event.key.mod & SDL_KMOD_NUM) ? (1 << 4) : 0) |
|
||||||
xmod |= (1 << 1);
|
((event.key.mod & SDL_KMOD_LEVEL5) ? (1 << 5) : 0) |
|
||||||
if (event.key.mod & SDL_KMOD_CTRL)
|
((event.key.mod & SDL_KMOD_GUI) ? (1 << 6) : 0) |
|
||||||
xmod |= (1 << 2);
|
((event.key.mod & SDL_KMOD_MODE) ? (1 << 7) : 0);
|
||||||
if (event.key.mod & SDL_KMOD_ALT)
|
|
||||||
xmod |= (1 << 3);
|
|
||||||
|
|
||||||
auto it = s_window_map.find(event.window.windowID);
|
auto it = s_window_map.find(event.window.windowID);
|
||||||
if (it != s_window_map.end())
|
if (it != s_window_map.end())
|
||||||
on_key_event(it->value->wid, scancode, xmod, (event.type == SDL_EVENT_KEY_DOWN));
|
on_key_event(it->value->wid, event.key.scancode, xmod, (event.type == SDL_EVENT_KEY_DOWN));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SDL_EVENT_KEYMAP_CHANGED:
|
||||||
|
sdl3_initialize_keymap();
|
||||||
|
on_keymap_changed();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdl3_invalidate(PlatformWindow* window, const uint32_t* src_pixels, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
static void sdl3_invalidate(PlatformWindow* window, const void* src_pixels, uint32_t src_pitch, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
auto& sdl_window = *static_cast<SDLWindow*>(window);
|
auto& sdl_window = *static_cast<SDLWindow*>(window);
|
||||||
|
|
||||||
@@ -316,16 +312,20 @@ static void sdl3_invalidate(PlatformWindow* window, const uint32_t* src_pixels,
|
|||||||
for (int32_t y_off = 0; y_off < rect.h; y_off++)
|
for (int32_t y_off = 0; y_off < rect.h; y_off++)
|
||||||
{
|
{
|
||||||
memcpy(
|
memcpy(
|
||||||
static_cast<uint8_t*>(dst_pixels) + y_off * dst_pitch,
|
static_cast< uint8_t*>(dst_pixels) + y_off * dst_pitch,
|
||||||
&src_pixels[(rect.y + y_off) * sdl_window.width + rect.x],
|
static_cast<const uint8_t*>(src_pixels) + y_off * src_pitch,
|
||||||
rect.w * sizeof(uint32_t)
|
rect.w * sizeof(uint32_t)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UnlockTexture(sdl_window.texture);
|
SDL_UnlockTexture(sdl_window.texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sdl3_end_frame(PlatformWindow* window)
|
||||||
|
{
|
||||||
|
auto& sdl_window = *static_cast<SDLWindow*>(window);
|
||||||
SDL_RenderClear(sdl_window.renderer);
|
SDL_RenderClear(sdl_window.renderer);
|
||||||
SDL_RenderTexture(sdl_window.renderer, sdl_window.texture, NULL, NULL);
|
SDL_RenderTexture(sdl_window.renderer, sdl_window.texture, nullptr, nullptr);
|
||||||
SDL_RenderPresent(sdl_window.renderer);
|
SDL_RenderPresent(sdl_window.renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,6 +438,8 @@ PlatformOps g_platform_ops = {
|
|||||||
.poll_events = sdl3_poll_events,
|
.poll_events = sdl3_poll_events,
|
||||||
.create_window = sdl3_create_window,
|
.create_window = sdl3_create_window,
|
||||||
.invalidate = sdl3_invalidate,
|
.invalidate = sdl3_invalidate,
|
||||||
|
.begin_frame = nullptr,
|
||||||
|
.end_frame = sdl3_end_frame,
|
||||||
.request_resize = sdl3_request_resize,
|
.request_resize = sdl3_request_resize,
|
||||||
.request_reposition = sdl3_request_reposition,
|
.request_reposition = sdl3_request_reposition,
|
||||||
.request_fullscreen = sdl3_request_fullscreen,
|
.request_fullscreen = sdl3_request_fullscreen,
|
||||||
@@ -449,124 +451,255 @@ PlatformOps g_platform_ops = {
|
|||||||
.set_cursor = sdl3_set_cursor,
|
.set_cursor = sdl3_set_cursor,
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <LibInput/KeyEvent.h>
|
static uint32_t sdl3_keycode_to_x_keysym(SDL_Keycode keycode);
|
||||||
|
|
||||||
consteval Keymap::Keymap()
|
static void sdl3_initialize_keymap()
|
||||||
{
|
{
|
||||||
for (auto& scancode : map)
|
static constexpr SDL_Keymod modifier_map[] {
|
||||||
scancode = 0;
|
SDL_KMOD_NONE,
|
||||||
|
SDL_KMOD_SHIFT,
|
||||||
|
SDL_KMOD_MODE,
|
||||||
|
SDL_KMOD_MODE | SDL_KMOD_SHIFT,
|
||||||
|
};
|
||||||
|
|
||||||
using LibInput::keycode_normal;
|
memset(g_keymap, 0, sizeof(g_keymap));
|
||||||
using LibInput::keycode_function;
|
memset(g_modifier_map, 0, sizeof(g_modifier_map));
|
||||||
using LibInput::keycode_numpad;
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_GRAVE] = keycode_normal(0, 0);
|
for (size_t scancode = 0; scancode < g_keymap_size; scancode++)
|
||||||
map[SDL_SCANCODE_1] = keycode_normal(0, 1);
|
for (size_t layer = 0; layer < g_keymap_layers; layer++)
|
||||||
map[SDL_SCANCODE_2] = keycode_normal(0, 2);
|
if (const auto sdl_key = SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(scancode), modifier_map[layer], false); sdl_key != SDLK_UNKNOWN)
|
||||||
map[SDL_SCANCODE_3] = keycode_normal(0, 3);
|
g_keymap[scancode][layer] = sdl3_keycode_to_x_keysym(sdl_key);
|
||||||
map[SDL_SCANCODE_4] = keycode_normal(0, 4);
|
|
||||||
map[SDL_SCANCODE_5] = keycode_normal(0, 5);
|
|
||||||
map[SDL_SCANCODE_6] = keycode_normal(0, 6);
|
|
||||||
map[SDL_SCANCODE_7] = keycode_normal(0, 7);
|
|
||||||
map[SDL_SCANCODE_8] = keycode_normal(0, 8);
|
|
||||||
map[SDL_SCANCODE_9] = keycode_normal(0, 9);
|
|
||||||
map[SDL_SCANCODE_0] = keycode_normal(0, 10);
|
|
||||||
map[SDL_SCANCODE_MINUS] = keycode_normal(0, 11);
|
|
||||||
map[SDL_SCANCODE_EQUALS] = keycode_normal(0, 12);
|
|
||||||
map[SDL_SCANCODE_BACKSPACE] = keycode_normal(0, 13);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_TAB] = keycode_normal(1, 0);
|
const auto get_scancode = [](SDL_Keycode keycode) -> uint8_t {
|
||||||
map[SDL_SCANCODE_Q] = keycode_normal(1, 1);
|
const auto scancode = SDL_GetScancodeFromKey(keycode, nullptr);;
|
||||||
map[SDL_SCANCODE_W] = keycode_normal(1, 2);
|
if (scancode != SDL_SCANCODE_UNKNOWN && scancode < g_keymap_size)
|
||||||
map[SDL_SCANCODE_E] = keycode_normal(1, 3);
|
return scancode + g_keymap_min_keycode;
|
||||||
map[SDL_SCANCODE_R] = keycode_normal(1, 4);
|
return 0;
|
||||||
map[SDL_SCANCODE_T] = keycode_normal(1, 5);
|
};
|
||||||
map[SDL_SCANCODE_Y] = keycode_normal(1, 6);
|
|
||||||
map[SDL_SCANCODE_U] = keycode_normal(1, 7);
|
|
||||||
map[SDL_SCANCODE_I] = keycode_normal(1, 8);
|
|
||||||
map[SDL_SCANCODE_O] = keycode_normal(1, 9);
|
|
||||||
map[SDL_SCANCODE_P] = keycode_normal(1, 10);
|
|
||||||
map[SDL_SCANCODE_LEFTBRACKET] = keycode_normal(1, 11);
|
|
||||||
map[SDL_SCANCODE_RIGHTBRACKET] = keycode_normal(1, 12);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_CAPSLOCK] = keycode_normal(2, 0);
|
g_modifier_map[0][0] = get_scancode(SDLK_LSHIFT);
|
||||||
map[SDL_SCANCODE_A] = keycode_normal(2, 1);
|
g_modifier_map[0][1] = get_scancode(SDLK_RSHIFT);
|
||||||
map[SDL_SCANCODE_S] = keycode_normal(2, 2);
|
|
||||||
map[SDL_SCANCODE_D] = keycode_normal(2, 3);
|
|
||||||
map[SDL_SCANCODE_F] = keycode_normal(2, 4);
|
|
||||||
map[SDL_SCANCODE_G] = keycode_normal(2, 5);
|
|
||||||
map[SDL_SCANCODE_H] = keycode_normal(2, 6);
|
|
||||||
map[SDL_SCANCODE_J] = keycode_normal(2, 7);
|
|
||||||
map[SDL_SCANCODE_K] = keycode_normal(2, 8);
|
|
||||||
map[SDL_SCANCODE_L] = keycode_normal(2, 9);
|
|
||||||
map[SDL_SCANCODE_SEMICOLON] = keycode_normal(2, 10);
|
|
||||||
map[SDL_SCANCODE_APOSTROPHE] = keycode_normal(2, 11);
|
|
||||||
map[SDL_SCANCODE_BACKSLASH] = keycode_normal(2, 12);
|
|
||||||
map[SDL_SCANCODE_RETURN] = keycode_normal(2, 13);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_LSHIFT] = keycode_normal(3, 0);
|
g_modifier_map[1][0] = get_scancode(SDLK_CAPSLOCK);
|
||||||
map[SDL_SCANCODE_NONUSBACKSLASH] = keycode_normal(3, 1);
|
|
||||||
map[SDL_SCANCODE_Z] = keycode_normal(3, 2);
|
|
||||||
map[SDL_SCANCODE_X] = keycode_normal(3, 3);
|
|
||||||
map[SDL_SCANCODE_C] = keycode_normal(3, 4);
|
|
||||||
map[SDL_SCANCODE_V] = keycode_normal(3, 5);
|
|
||||||
map[SDL_SCANCODE_B] = keycode_normal(3, 6);
|
|
||||||
map[SDL_SCANCODE_N] = keycode_normal(3, 7);
|
|
||||||
map[SDL_SCANCODE_M] = keycode_normal(3, 8);
|
|
||||||
map[SDL_SCANCODE_COMMA] = keycode_normal(3, 9);
|
|
||||||
map[SDL_SCANCODE_PERIOD] = keycode_normal(3, 10);
|
|
||||||
map[SDL_SCANCODE_SLASH] = keycode_normal(3, 11);
|
|
||||||
map[SDL_SCANCODE_RSHIFT] = keycode_normal(3, 12);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_LCTRL] = keycode_normal(4, 0);
|
g_modifier_map[2][0] = get_scancode(SDLK_LCTRL);
|
||||||
map[SDL_SCANCODE_LGUI] = keycode_normal(4, 1);
|
g_modifier_map[2][1] = get_scancode(SDLK_RCTRL);
|
||||||
map[SDL_SCANCODE_LALT] = keycode_normal(4, 2);
|
|
||||||
map[SDL_SCANCODE_SPACE] = keycode_normal(4, 3);
|
|
||||||
map[SDL_SCANCODE_RALT] = keycode_normal(4, 4);
|
|
||||||
map[SDL_SCANCODE_RCTRL] = keycode_normal(4, 5);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_UP] = keycode_normal(5, 0);
|
g_modifier_map[3][0] = get_scancode(SDLK_LALT);
|
||||||
map[SDL_SCANCODE_LEFT] = keycode_normal(5, 1);
|
g_modifier_map[3][1] = get_scancode(SDLK_RALT);
|
||||||
map[SDL_SCANCODE_DOWN] = keycode_normal(5, 2);
|
|
||||||
map[SDL_SCANCODE_RIGHT] = keycode_normal(5, 3);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_ESCAPE] = keycode_function(0);
|
g_modifier_map[4][0] = get_scancode(SDLK_NUMLOCKCLEAR);
|
||||||
map[SDL_SCANCODE_F1] = keycode_function(1);
|
|
||||||
map[SDL_SCANCODE_F2] = keycode_function(2);
|
|
||||||
map[SDL_SCANCODE_F3] = keycode_function(3);
|
|
||||||
map[SDL_SCANCODE_F4] = keycode_function(4);
|
|
||||||
map[SDL_SCANCODE_F5] = keycode_function(5);
|
|
||||||
map[SDL_SCANCODE_F6] = keycode_function(6);
|
|
||||||
map[SDL_SCANCODE_F7] = keycode_function(7);
|
|
||||||
map[SDL_SCANCODE_F8] = keycode_function(8);
|
|
||||||
map[SDL_SCANCODE_F9] = keycode_function(9);
|
|
||||||
map[SDL_SCANCODE_F10] = keycode_function(10);
|
|
||||||
map[SDL_SCANCODE_F11] = keycode_function(11);
|
|
||||||
map[SDL_SCANCODE_F12] = keycode_function(12);
|
|
||||||
map[SDL_SCANCODE_INSERT] = keycode_function(13);
|
|
||||||
map[SDL_SCANCODE_PRINTSCREEN] = keycode_function(14);
|
|
||||||
map[SDL_SCANCODE_DELETE] = keycode_function(15);
|
|
||||||
map[SDL_SCANCODE_HOME] = keycode_function(16);
|
|
||||||
map[SDL_SCANCODE_END] = keycode_function(17);
|
|
||||||
map[SDL_SCANCODE_PAGEUP] = keycode_function(18);
|
|
||||||
map[SDL_SCANCODE_PAGEDOWN] = keycode_function(19);
|
|
||||||
map[SDL_SCANCODE_SCROLLLOCK] = keycode_function(20);
|
|
||||||
|
|
||||||
map[SDL_SCANCODE_NUMLOCKCLEAR] = keycode_numpad(0, 0);
|
g_modifier_map[5][0] = get_scancode(SDLK_LEVEL5_SHIFT);
|
||||||
map[SDL_SCANCODE_KP_DIVIDE] = keycode_numpad(0, 1);
|
|
||||||
map[SDL_SCANCODE_KP_MULTIPLY] = keycode_numpad(0, 2);
|
g_modifier_map[6][0] = get_scancode(SDLK_LGUI);
|
||||||
map[SDL_SCANCODE_KP_MINUS] = keycode_numpad(0, 3);
|
g_modifier_map[6][1] = get_scancode(SDLK_RGUI);
|
||||||
map[SDL_SCANCODE_KP_7] = keycode_numpad(1, 0);
|
|
||||||
map[SDL_SCANCODE_KP_8] = keycode_numpad(1, 1);
|
g_modifier_map[7][0] = get_scancode(SDLK_MODE);
|
||||||
map[SDL_SCANCODE_KP_9] = keycode_numpad(1, 2);
|
}
|
||||||
map[SDL_SCANCODE_KP_PLUS] = keycode_numpad(1, 3);
|
|
||||||
map[SDL_SCANCODE_KP_4] = keycode_numpad(2, 0);
|
#include <X11/keysym.h>
|
||||||
map[SDL_SCANCODE_KP_5] = keycode_numpad(2, 1);
|
#include <X11/XF86keysym.h>
|
||||||
map[SDL_SCANCODE_KP_6] = keycode_numpad(2, 2);
|
|
||||||
map[SDL_SCANCODE_KP_1] = keycode_numpad(3, 0);
|
#include <wctype.h>
|
||||||
map[SDL_SCANCODE_KP_2] = keycode_numpad(3, 1);
|
|
||||||
map[SDL_SCANCODE_KP_3] = keycode_numpad(3, 2);
|
static uint32_t sdl3_keycode_to_x_keysym(SDL_Keycode keycode)
|
||||||
map[SDL_SCANCODE_KP_ENTER] = keycode_numpad(3, 3);
|
{
|
||||||
map[SDL_SCANCODE_KP_0] = keycode_numpad(4, 0);
|
if (iswprint(keycode))
|
||||||
map[SDL_SCANCODE_KP_COMMA] = keycode_numpad(4, 1);
|
{
|
||||||
};
|
if (keycode >= 0x100)
|
||||||
|
keycode |= 0x01000000;
|
||||||
|
return keycode;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (keycode)
|
||||||
|
{
|
||||||
|
case SDLK_RETURN: return XK_Return;
|
||||||
|
case SDLK_ESCAPE: return XK_Escape;
|
||||||
|
case SDLK_BACKSPACE: return XK_BackSpace;
|
||||||
|
case SDLK_TAB: return XK_Tab;
|
||||||
|
case SDLK_DELETE: return XK_Delete;
|
||||||
|
case SDLK_CAPSLOCK: return XK_Caps_Lock;
|
||||||
|
case SDLK_F1: return XK_F1;
|
||||||
|
case SDLK_F2: return XK_F2;
|
||||||
|
case SDLK_F3: return XK_F3;
|
||||||
|
case SDLK_F4: return XK_F4;
|
||||||
|
case SDLK_F5: return XK_F5;
|
||||||
|
case SDLK_F6: return XK_F6;
|
||||||
|
case SDLK_F7: return XK_F7;
|
||||||
|
case SDLK_F8: return XK_F8;
|
||||||
|
case SDLK_F9: return XK_F9;
|
||||||
|
case SDLK_F10: return XK_F10;
|
||||||
|
case SDLK_F11: return XK_F11;
|
||||||
|
case SDLK_F12: return XK_F12;
|
||||||
|
case SDLK_PRINTSCREEN: return XK_Print;
|
||||||
|
case SDLK_SCROLLLOCK: return XK_Scroll_Lock;
|
||||||
|
case SDLK_PAUSE: return XK_Pause;
|
||||||
|
case SDLK_INSERT: return XK_Insert;
|
||||||
|
case SDLK_HOME: return XK_Home;
|
||||||
|
case SDLK_PAGEUP: return XK_Page_Up;
|
||||||
|
case SDLK_END: return XK_End;
|
||||||
|
case SDLK_PAGEDOWN: return XK_Page_Down;
|
||||||
|
case SDLK_RIGHT: return XK_Right;
|
||||||
|
case SDLK_LEFT: return XK_Left;
|
||||||
|
case SDLK_DOWN: return XK_Down;
|
||||||
|
case SDLK_UP: return XK_Up;
|
||||||
|
case SDLK_NUMLOCKCLEAR: return XK_Num_Lock;
|
||||||
|
case SDLK_KP_DIVIDE: return XK_KP_Divide;
|
||||||
|
case SDLK_KP_MULTIPLY: return XK_KP_Multiply;
|
||||||
|
case SDLK_KP_MINUS: return XK_KP_Subtract;
|
||||||
|
case SDLK_KP_PLUS: return XK_KP_Add;
|
||||||
|
case SDLK_KP_ENTER: return XK_KP_Enter;
|
||||||
|
case SDLK_KP_1: return XK_KP_1;
|
||||||
|
case SDLK_KP_2: return XK_KP_2;
|
||||||
|
case SDLK_KP_3: return XK_KP_3;
|
||||||
|
case SDLK_KP_4: return XK_KP_4;
|
||||||
|
case SDLK_KP_5: return XK_KP_5;
|
||||||
|
case SDLK_KP_6: return XK_KP_6;
|
||||||
|
case SDLK_KP_7: return XK_KP_7;
|
||||||
|
case SDLK_KP_8: return XK_KP_8;
|
||||||
|
case SDLK_KP_9: return XK_KP_9;
|
||||||
|
case SDLK_KP_0: return XK_KP_0;
|
||||||
|
case SDLK_KP_PERIOD: return XK_KP_Decimal;
|
||||||
|
case SDLK_APPLICATION: return XF86XK_ApplicationLeft;
|
||||||
|
case SDLK_POWER: return XF86XK_PowerOff;
|
||||||
|
case SDLK_KP_EQUALS: return XK_KP_Equal;
|
||||||
|
case SDLK_F13: return XK_F13;
|
||||||
|
case SDLK_F14: return XK_F14;
|
||||||
|
case SDLK_F15: return XK_F15;
|
||||||
|
case SDLK_F16: return XK_F16;
|
||||||
|
case SDLK_F17: return XK_F17;
|
||||||
|
case SDLK_F18: return XK_F18;
|
||||||
|
case SDLK_F19: return XK_F19;
|
||||||
|
case SDLK_F20: return XK_F20;
|
||||||
|
case SDLK_F21: return XK_F21;
|
||||||
|
case SDLK_F22: return XK_F22;
|
||||||
|
case SDLK_F23: return XK_F23;
|
||||||
|
case SDLK_F24: return XK_F24;
|
||||||
|
case SDLK_EXECUTE: return XK_Execute;
|
||||||
|
case SDLK_HELP: return XK_Help;
|
||||||
|
case SDLK_MENU: return XK_Menu;
|
||||||
|
case SDLK_SELECT: return XK_Select;
|
||||||
|
case SDLK_STOP: return XF86XK_Stop;
|
||||||
|
case SDLK_AGAIN: return XK_Redo;
|
||||||
|
case SDLK_UNDO: return XK_Undo;
|
||||||
|
case SDLK_CUT: return XF86XK_Cut;
|
||||||
|
case SDLK_COPY: return XF86XK_Copy;
|
||||||
|
case SDLK_PASTE: return XF86XK_Paste;
|
||||||
|
case SDLK_FIND: return XK_Find;
|
||||||
|
case SDLK_MUTE: return XF86XK_AudioMute;
|
||||||
|
case SDLK_VOLUMEUP: return XF86XK_AudioRaiseVolume;
|
||||||
|
case SDLK_VOLUMEDOWN: return XF86XK_AudioLowerVolume;
|
||||||
|
case SDLK_KP_COMMA: return XK_KP_Separator;
|
||||||
|
//case SDLK_KP_EQUALSAS400: return ;
|
||||||
|
//case SDLK_ALTERASE: return ;
|
||||||
|
case SDLK_SYSREQ: return XK_Sys_Req;
|
||||||
|
case SDLK_CANCEL: return XK_Cancel;
|
||||||
|
case SDLK_CLEAR: return XK_Clear;
|
||||||
|
case SDLK_PRIOR: return XK_Prior;
|
||||||
|
case SDLK_RETURN2: return XK_Return;
|
||||||
|
//case SDLK_SEPARATOR: return ;
|
||||||
|
//case SDLK_OUT: return ;
|
||||||
|
//case SDLK_OPER: return ;
|
||||||
|
//case SDLK_CLEARAGAIN: return ;
|
||||||
|
//case SDLK_CRSEL: return ;
|
||||||
|
//case SDLK_EXSEL: return ;
|
||||||
|
//case SDLK_KP_00: return ;
|
||||||
|
//case SDLK_KP_000: return ;
|
||||||
|
//case SDLK_THOUSANDSSEPARATOR: return ;
|
||||||
|
//case SDLK_DECIMALSEPARATOR: return ;
|
||||||
|
//case SDLK_CURRENCYUNIT: return ;
|
||||||
|
//case SDLK_CURRENCYSUBUNIT: return ;
|
||||||
|
//case SDLK_KP_LEFTPAREN: return ;
|
||||||
|
//case SDLK_KP_RIGHTPAREN: return ;
|
||||||
|
//case SDLK_KP_LEFTBRACE: return ;
|
||||||
|
//case SDLK_KP_RIGHTBRACE: return ;
|
||||||
|
case SDLK_KP_TAB: return XK_KP_Tab;
|
||||||
|
//case SDLK_KP_BACKSPACE: return ;
|
||||||
|
//case SDLK_KP_A: return ;
|
||||||
|
//case SDLK_KP_B: return ;
|
||||||
|
//case SDLK_KP_C: return ;
|
||||||
|
//case SDLK_KP_D: return ;
|
||||||
|
//case SDLK_KP_E: return ;
|
||||||
|
//case SDLK_KP_F: return ;
|
||||||
|
//case SDLK_KP_XOR: return ;
|
||||||
|
//case SDLK_KP_POWER: return ;
|
||||||
|
//case SDLK_KP_PERCENT: return ;
|
||||||
|
//case SDLK_KP_LESS: return ;
|
||||||
|
//case SDLK_KP_GREATER: return ;
|
||||||
|
//case SDLK_KP_AMPERSAND: return ;
|
||||||
|
//case SDLK_KP_DBLAMPERSAND: return ;
|
||||||
|
//case SDLK_KP_VERTICALBAR: return ;
|
||||||
|
//case SDLK_KP_DBLVERTICALBAR: return ;
|
||||||
|
//case SDLK_KP_COLON: return ;
|
||||||
|
//case SDLK_KP_HASH: return ;
|
||||||
|
//case SDLK_KP_SPACE: return ;
|
||||||
|
//case SDLK_KP_AT: return ;
|
||||||
|
//case SDLK_KP_EXCLAM: return ;
|
||||||
|
//case SDLK_KP_MEMSTORE: return ;
|
||||||
|
//case SDLK_KP_MEMRECALL: return ;
|
||||||
|
//case SDLK_KP_MEMCLEAR: return ;
|
||||||
|
//case SDLK_KP_MEMADD: return ;
|
||||||
|
//case SDLK_KP_MEMSUBTRACT: return ;
|
||||||
|
//case SDLK_KP_MEMMULTIPLY: return ;
|
||||||
|
//case SDLK_KP_MEMDIVIDE: return ;
|
||||||
|
//case SDLK_KP_PLUSMINUS: return ;
|
||||||
|
//case SDLK_KP_CLEAR: return ;
|
||||||
|
//case SDLK_KP_CLEARENTRY: return ;
|
||||||
|
//case SDLK_KP_BINARY: return ;
|
||||||
|
//case SDLK_KP_OCTAL: return ;
|
||||||
|
//case SDLK_KP_DECIMAL: return ;
|
||||||
|
//case SDLK_KP_HEXADECIMAL: return ;
|
||||||
|
case SDLK_LCTRL: return XK_Control_L;
|
||||||
|
case SDLK_LSHIFT: return XK_Shift_L;
|
||||||
|
case SDLK_LALT: return XK_Alt_L;
|
||||||
|
case SDLK_LGUI: return XK_Super_L;
|
||||||
|
case SDLK_RCTRL: return XK_Control_R;
|
||||||
|
case SDLK_RSHIFT: return XK_Shift_R;
|
||||||
|
case SDLK_RALT: return XK_Alt_R;
|
||||||
|
case SDLK_RGUI: return XK_Super_R;
|
||||||
|
case SDLK_MODE: return XK_Mode_switch;
|
||||||
|
case SDLK_SLEEP: return XF86XK_Sleep;
|
||||||
|
case SDLK_WAKE: return XF86XK_WakeUp;
|
||||||
|
//case SDLK_CHANNEL_INCREMENT: return XF86XK_ChannelUp;
|
||||||
|
//case SDLK_CHANNEL_DECREMENT: return XF86XK_ChannelDown;
|
||||||
|
case SDLK_MEDIA_PLAY: return XF86XK_AudioPlay;
|
||||||
|
case SDLK_MEDIA_PAUSE: return XF86XK_AudioPause;
|
||||||
|
case SDLK_MEDIA_RECORD: return XF86XK_AudioRecord;
|
||||||
|
case SDLK_MEDIA_FAST_FORWARD: return XF86XK_AudioForward;
|
||||||
|
case SDLK_MEDIA_REWIND: return XF86XK_AudioRewind;
|
||||||
|
case SDLK_MEDIA_NEXT_TRACK: return XF86XK_AudioNext;
|
||||||
|
case SDLK_MEDIA_PREVIOUS_TRACK: return XF86XK_AudioPrev;
|
||||||
|
case SDLK_MEDIA_STOP: return XF86XK_AudioStop;
|
||||||
|
case SDLK_MEDIA_EJECT: return XF86XK_Eject;
|
||||||
|
//case SDLK_MEDIA_PLAY_PAUSE: return XF86XK_MediaPlayPause;
|
||||||
|
case SDLK_MEDIA_SELECT: return XF86XK_AudioMedia;
|
||||||
|
case SDLK_AC_NEW: return XF86XK_New;
|
||||||
|
case SDLK_AC_OPEN: return XF86XK_Open;
|
||||||
|
case SDLK_AC_CLOSE: return XF86XK_Close;
|
||||||
|
//case SDLK_AC_EXIT: return XF86XK_Exit;
|
||||||
|
case SDLK_AC_SAVE: return XF86XK_Save;
|
||||||
|
case SDLK_AC_PRINT: return XK_Print;
|
||||||
|
//case SDLK_AC_PROPERTIES: return ;
|
||||||
|
case SDLK_AC_SEARCH: return XF86XK_Search;
|
||||||
|
case SDLK_AC_HOME: return XF86XK_HomePage; // ?
|
||||||
|
case SDLK_AC_BACK: return XF86XK_Back;
|
||||||
|
case SDLK_AC_FORWARD: return XF86XK_Forward;
|
||||||
|
case SDLK_AC_STOP: return XF86XK_Stop;
|
||||||
|
case SDLK_AC_REFRESH: return XF86XK_Refresh;
|
||||||
|
case SDLK_AC_BOOKMARKS: return XF86XK_Book; // ?
|
||||||
|
//case SDLK_SOFTLEFT: return ;
|
||||||
|
//case SDLK_SOFTRIGHT: return ;
|
||||||
|
//case SDLK_CALL: return ;
|
||||||
|
//case SDLK_ENDCALL: return ;
|
||||||
|
case SDLK_LEFT_TAB: return XK_ISO_Left_Tab;
|
||||||
|
case SDLK_LEVEL5_SHIFT: return XK_ISO_Level5_Shift;
|
||||||
|
case SDLK_MULTI_KEY_COMPOSE: return XK_Multi_key;
|
||||||
|
case SDLK_LMETA: return XK_Meta_L;
|
||||||
|
case SDLK_RMETA: return XK_Meta_R;
|
||||||
|
case SDLK_LHYPER: return XK_Hyper_L;
|
||||||
|
case SDLK_RHYPER: return XK_Hyper_R;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "../Events.h"
|
#include "../Events.h"
|
||||||
|
#include "../Keymap.h"
|
||||||
#include "../Platform.h"
|
#include "../Platform.h"
|
||||||
|
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
@@ -25,7 +26,11 @@ struct BananCursor final : public PlatformCursor
|
|||||||
int32_t origin_y;
|
int32_t origin_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool bananos_initialize(uint32_t* display_w, uint32_t* display_h)
|
static BAN::UniqPtr<LibGUI::Window> s_dummy_window;
|
||||||
|
|
||||||
|
static BAN::ErrorOr<void> bananos_initialize_keymap();
|
||||||
|
|
||||||
|
static bool bananos_initialize()
|
||||||
{
|
{
|
||||||
auto attributes = LibGUI::Window::default_attributes;
|
auto attributes = LibGUI::Window::default_attributes;
|
||||||
attributes.shown = false;
|
attributes.shown = false;
|
||||||
@@ -37,8 +42,15 @@ static bool bananos_initialize(uint32_t* display_w, uint32_t* display_h)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*display_w = dummy_or_error.value()->width();
|
s_dummy_window = dummy_or_error.release_value();
|
||||||
*display_h = dummy_or_error.value()->height();
|
|
||||||
|
register_display(0, 0, s_dummy_window->width(), s_dummy_window->height());
|
||||||
|
|
||||||
|
if (auto ret = bananos_initialize_keymap(); ret.is_error())
|
||||||
|
{
|
||||||
|
dwarnln("Could not initialize keymap: {}", ret.error());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -49,12 +61,9 @@ static void bananos_poll_events(void* window)
|
|||||||
banan_window.window->poll_events();
|
banan_window.window->poll_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(PlatformWindow* parent, WindowType type, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height)
|
static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(WindowType type, WINDOW wid, int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
(void)parent;
|
|
||||||
(void)type;
|
(void)type;
|
||||||
(void)x;
|
|
||||||
(void)y;
|
|
||||||
|
|
||||||
auto window = TRY(BAN::UniqPtr<BananWindow>::create());
|
auto window = TRY(BAN::UniqPtr<BananWindow>::create());
|
||||||
|
|
||||||
@@ -62,10 +71,14 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(Platform
|
|||||||
attributes.shown = true;
|
attributes.shown = true;
|
||||||
attributes.title_bar = false;
|
attributes.title_bar = false;
|
||||||
attributes.resizable = true;
|
attributes.resizable = true;
|
||||||
|
attributes.alpha_channel = true;
|
||||||
|
|
||||||
auto gui_window = TRY(LibGUI::Window::create(width, height, ""_sv, attributes));
|
auto gui_window = TRY(LibGUI::Window::create(width, height, ""_sv, attributes));
|
||||||
auto* winp = gui_window.ptr();
|
auto* winp = gui_window.ptr();
|
||||||
|
|
||||||
|
if (x != 0 || y != 0)
|
||||||
|
gui_window->set_position(x, y);
|
||||||
|
|
||||||
gui_window->set_close_window_event_callback([wid] {
|
gui_window->set_close_window_event_callback([wid] {
|
||||||
on_window_close_event(wid);
|
on_window_close_event(wid);
|
||||||
});
|
});
|
||||||
@@ -78,6 +91,9 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(Platform
|
|||||||
gui_window->set_window_fullscreen_event_callback([wid](auto event) {
|
gui_window->set_window_fullscreen_event_callback([wid](auto event) {
|
||||||
on_window_fullscreen_event(wid, event.fullscreen);
|
on_window_fullscreen_event(wid, event.fullscreen);
|
||||||
});
|
});
|
||||||
|
gui_window->set_window_move_event_callback([wid](auto event) {
|
||||||
|
on_window_move_event(wid, event.x, event.y);
|
||||||
|
});
|
||||||
gui_window->set_mouse_move_event_callback([wid](auto event) {
|
gui_window->set_mouse_move_event_callback([wid](auto event) {
|
||||||
on_mouse_move_event(wid, event.x, event.y);
|
on_mouse_move_event(wid, event.x, event.y);
|
||||||
});
|
});
|
||||||
@@ -103,7 +119,11 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(Platform
|
|||||||
(event.shift() ? (1 << 0) : 0) |
|
(event.shift() ? (1 << 0) : 0) |
|
||||||
(event.caps_lock() ? (1 << 1) : 0) |
|
(event.caps_lock() ? (1 << 1) : 0) |
|
||||||
(event.ctrl() ? (1 << 2) : 0) |
|
(event.ctrl() ? (1 << 2) : 0) |
|
||||||
(event.alt() ? (1 << 3) : 0);
|
(event.alt() ? (1 << 3) : 0) |
|
||||||
|
(event.num_lock() ? (1 << 4) : 0) |
|
||||||
|
// level5 shift
|
||||||
|
// super
|
||||||
|
(event.ralt() ? (1 << 7) : 0); // FIXME: altgr
|
||||||
on_key_event(wid, event.scancode, xmod, event.pressed());
|
on_key_event(wid, event.scancode, xmod, event.pressed());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,23 +142,32 @@ static void bananos_request_resize(PlatformWindow* window, uint32_t width, uint3
|
|||||||
|
|
||||||
static void bananos_request_reposition(PlatformWindow* window, int32_t x, int32_t y)
|
static void bananos_request_reposition(PlatformWindow* window, int32_t x, int32_t y)
|
||||||
{
|
{
|
||||||
(void)window;
|
auto& banan_window = *static_cast<BananWindow*>(window);
|
||||||
(void)x;
|
banan_window.window->set_position(x, y);
|
||||||
(void)y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bananos_invalidate(PlatformWindow* window, const uint32_t* pixels, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
static void bananos_invalidate(PlatformWindow* window, const void* src_pixels, uint32_t src_pitch, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
auto& banan_window = *static_cast<BananWindow*>(window);
|
auto& banan_window = *static_cast<BananWindow*>(window);
|
||||||
|
|
||||||
const uint32_t win_width = banan_window.window->width();
|
auto& texture = banan_window.window->texture();
|
||||||
|
void* dst_pixels = &texture.pixels()[y * texture.width() + x];
|
||||||
|
const uint32_t dst_pitch = texture.width() * sizeof(uint32_t);
|
||||||
|
|
||||||
auto* out_pixels = banan_window.window->texture().pixels().data();
|
|
||||||
for (uint32_t y_off = 0; y_off < height; y_off++)
|
for (uint32_t y_off = 0; y_off < height; y_off++)
|
||||||
for (uint32_t x_off = 0; x_off < width; x_off++)
|
{
|
||||||
out_pixels[(y + y_off) * win_width + (x + x_off)] = pixels[(y + y_off) * win_width + (x + x_off)];
|
memcpy(
|
||||||
|
static_cast< uint8_t*>(dst_pixels) + y_off * dst_pitch,
|
||||||
|
static_cast<const uint8_t*>(src_pixels) + y_off * src_pitch,
|
||||||
|
width * sizeof(uint32_t)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
banan_window.window->invalidate(x, y, width, height);
|
static void bananos_end_frame(PlatformWindow* window)
|
||||||
|
{
|
||||||
|
auto& banan_window = *static_cast<BananWindow*>(window);
|
||||||
|
banan_window.window->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
|
static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
|
||||||
@@ -147,29 +176,24 @@ static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
|
|||||||
banan_window.window->set_fullscreen(fullscreen);
|
banan_window.window->set_fullscreen(fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bananos_warp_pointer(int32_t x, int32_t y, bool relative)
|
static void bananos_query_ponter(int32_t* x, int32_t* y)
|
||||||
{
|
{
|
||||||
(void)x;
|
s_dummy_window->query_cursor_position();
|
||||||
(void)y;
|
|
||||||
(void)relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bananos_query_pointer(int32_t* x, int32_t* y)
|
bool queried { false };
|
||||||
{
|
s_dummy_window->set_query_pointer_event_callback([&](auto event) {
|
||||||
(void)x;
|
*x = event.x;
|
||||||
(void)y;
|
*y = event.y;
|
||||||
}
|
queried = true;
|
||||||
|
});
|
||||||
|
|
||||||
static void bananos_set_pointer_grab(PlatformWindow* window, bool grabbed)
|
while (!queried)
|
||||||
{
|
{
|
||||||
(void)window;
|
s_dummy_window->wait_events();
|
||||||
(void)grabbed;
|
s_dummy_window->poll_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_system_cursor(SystemCursorType type)
|
s_dummy_window->set_query_pointer_event_callback({});
|
||||||
{
|
|
||||||
(void)type;
|
|
||||||
return BAN::Error::from_errno(ENOTSUP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_bitmap_cursor(const uint32_t* pixels, uint32_t width, uint32_t height, int32_t origin_x, int32_t origin_y)
|
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_bitmap_cursor(const uint32_t* pixels, uint32_t width, uint32_t height, int32_t origin_x, int32_t origin_y)
|
||||||
@@ -206,13 +230,161 @@ PlatformOps g_platform_ops = {
|
|||||||
.poll_events = bananos_poll_events,
|
.poll_events = bananos_poll_events,
|
||||||
.create_window = bananos_create_window,
|
.create_window = bananos_create_window,
|
||||||
.invalidate = bananos_invalidate,
|
.invalidate = bananos_invalidate,
|
||||||
|
.begin_frame = nullptr,
|
||||||
|
.end_frame = bananos_end_frame,
|
||||||
.request_resize = bananos_request_resize,
|
.request_resize = bananos_request_resize,
|
||||||
.request_reposition = bananos_request_reposition,
|
.request_reposition = bananos_request_reposition,
|
||||||
.request_fullscreen = bananos_request_fullscreen,
|
.request_fullscreen = bananos_request_fullscreen,
|
||||||
.warp_pointer = bananos_warp_pointer,
|
.warp_pointer = nullptr,
|
||||||
.query_pointer = nullptr, /* bananos_query_pointer */
|
.query_pointer = bananos_query_ponter,
|
||||||
.set_pointer_grab = bananos_set_pointer_grab,
|
.set_pointer_grab = nullptr,
|
||||||
.create_system_cursor = bananos_create_system_cursor,
|
.create_system_cursor = nullptr,
|
||||||
.create_bitmap_cursor = bananos_create_bitmap_cursor,
|
.create_bitmap_cursor = bananos_create_bitmap_cursor,
|
||||||
.set_cursor = bananos_set_cursor,
|
.set_cursor = bananos_set_cursor,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <LibInput/KeyboardLayout.h>
|
||||||
|
#include <LibInput/KeyEvent.h>
|
||||||
|
|
||||||
|
static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event);
|
||||||
|
|
||||||
|
static BAN::ErrorOr<void> bananos_initialize_keymap()
|
||||||
|
{
|
||||||
|
static constexpr uint16_t modifier_map[] {
|
||||||
|
0,
|
||||||
|
LibInput::KeyEvent::LShift,
|
||||||
|
LibInput::KeyEvent::RAlt,
|
||||||
|
LibInput::KeyEvent::RAlt | LibInput::KeyEvent::LShift,
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: get this from somewhere (gui command? enviroment? tmp file?)
|
||||||
|
const auto keymap_path = "./us.keymap"_sv;
|
||||||
|
TRY(LibInput::KeyboardLayout::initialize());
|
||||||
|
auto& keyboard_layout = LibInput::KeyboardLayout::get();
|
||||||
|
TRY(keyboard_layout.load_from_file(keymap_path));
|
||||||
|
|
||||||
|
for (uint8_t scancode = 0; scancode < g_keymap_size; scancode++)
|
||||||
|
for (size_t layer = 0; layer < g_keymap_layers; layer++)
|
||||||
|
if (const auto event = keyboard_layout.key_event_from_raw({ .modifier = modifier_map[layer], .keycode = scancode }); event.key != LibInput::Key::None)
|
||||||
|
g_keymap[scancode][layer] = bananos_keyevent_to_x_keysym(event);
|
||||||
|
|
||||||
|
using LibInput::keycode_normal;
|
||||||
|
using LibInput::keycode_numpad;
|
||||||
|
|
||||||
|
g_modifier_map[0][0] = keycode_normal(3, 0) + g_keymap_min_keycode; // lshift
|
||||||
|
g_modifier_map[0][1] = keycode_normal(3, 12) + g_keymap_min_keycode; // rshift
|
||||||
|
|
||||||
|
g_modifier_map[1][0] = keycode_normal(2, 0) + g_keymap_min_keycode; // caps lock
|
||||||
|
|
||||||
|
g_modifier_map[2][0] = keycode_normal(4, 0) + g_keymap_min_keycode; // lctrl
|
||||||
|
g_modifier_map[2][1] = keycode_normal(4, 6) + g_keymap_min_keycode; // rctrl
|
||||||
|
|
||||||
|
g_modifier_map[3][0] = keycode_normal(4, 2) + g_keymap_min_keycode; // lalt
|
||||||
|
g_modifier_map[3][1] = keycode_normal(4, 5) + g_keymap_min_keycode; // ralt
|
||||||
|
|
||||||
|
g_modifier_map[4][0] = keycode_numpad(0, 0) + g_keymap_min_keycode; // num lock
|
||||||
|
|
||||||
|
//g_modifier_map[5][0] = level5 shift;
|
||||||
|
|
||||||
|
g_modifier_map[6][0] = keycode_normal(4, 1) + g_keymap_min_keycode; // lsuper
|
||||||
|
g_modifier_map[6][1] = keycode_normal(4, 4) + g_keymap_min_keycode; // rsuper
|
||||||
|
|
||||||
|
g_modifier_map[7][0] = keycode_normal(4, 5) + g_keymap_min_keycode; // FIXME: altgr
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <BAN/UTF8.h>
|
||||||
|
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
#include <X11/XF86keysym.h>
|
||||||
|
|
||||||
|
#include <wctype.h>
|
||||||
|
|
||||||
|
static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event)
|
||||||
|
{
|
||||||
|
using namespace LibInput;
|
||||||
|
|
||||||
|
if (const char* utf8 = key_to_utf8(event.key, event.modifier))
|
||||||
|
{
|
||||||
|
uint32_t codepoint = BAN::UTF8::to_codepoint(utf8);
|
||||||
|
if (codepoint != BAN::UTF8::invalid && iswprint(codepoint))
|
||||||
|
{
|
||||||
|
if (codepoint >= 0x100)
|
||||||
|
codepoint |= 0x01000000;
|
||||||
|
return codepoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.key)
|
||||||
|
{
|
||||||
|
case Key::F1: return XK_F1;
|
||||||
|
case Key::F2: return XK_F2;
|
||||||
|
case Key::F3: return XK_F3;
|
||||||
|
case Key::F4: return XK_F4;
|
||||||
|
case Key::F5: return XK_F5;
|
||||||
|
case Key::F6: return XK_F6;
|
||||||
|
case Key::F7: return XK_F7;
|
||||||
|
case Key::F8: return XK_F8;
|
||||||
|
case Key::F9: return XK_F9;
|
||||||
|
case Key::F10: return XK_F10;
|
||||||
|
case Key::F11: return XK_F11;
|
||||||
|
case Key::F12: return XK_F12;
|
||||||
|
case Key::Insert: return XK_Insert;
|
||||||
|
case Key::PrintScreen: return XK_Print;
|
||||||
|
case Key::Delete: return XK_Delete;
|
||||||
|
case Key::Home: return XK_Home;
|
||||||
|
case Key::End: return XK_End;
|
||||||
|
case Key::PageUp: return XK_Page_Up;
|
||||||
|
case Key::PageDown: return XK_Page_Down;
|
||||||
|
case Key::Enter: return XK_Return;
|
||||||
|
case Key::Backspace: return XK_BackSpace;
|
||||||
|
case Key::Escape: return XK_Escape;
|
||||||
|
case Key::Tab: return XK_Tab;
|
||||||
|
case Key::CapsLock: return XK_Caps_Lock;
|
||||||
|
case Key::LeftShift: return XK_Shift_L;
|
||||||
|
case Key::LeftCtrl: return XK_Control_L;
|
||||||
|
case Key::LeftSuper: return XK_Super_L;
|
||||||
|
case Key::LeftAlt: return XK_Alt_L;
|
||||||
|
case Key::RightAlt: return XK_Alt_R;
|
||||||
|
case Key::RightSuper: return XK_Super_R;
|
||||||
|
case Key::RightCtrl: return XK_Control_R;
|
||||||
|
case Key::RightShift: return XK_Shift_R;
|
||||||
|
case Key::ArrowUp: return XK_Up;
|
||||||
|
case Key::ArrowDown: return XK_Down;
|
||||||
|
case Key::ArrowLeft: return XK_Left;
|
||||||
|
case Key::ArrowRight: return XK_Right;
|
||||||
|
case Key::NumLock: return XK_Num_Lock;
|
||||||
|
case Key::ScrollLock: return XK_Scroll_Lock;
|
||||||
|
case Key::Numpad0: return XK_KP_0;
|
||||||
|
case Key::Numpad1: return XK_KP_1;
|
||||||
|
case Key::Numpad2: return XK_KP_2;
|
||||||
|
case Key::Numpad3: return XK_KP_3;
|
||||||
|
case Key::Numpad4: return XK_KP_4;
|
||||||
|
case Key::Numpad5: return XK_KP_5;
|
||||||
|
case Key::Numpad6: return XK_KP_6;
|
||||||
|
case Key::Numpad7: return XK_KP_7;
|
||||||
|
case Key::Numpad8: return XK_KP_8;
|
||||||
|
case Key::Numpad9: return XK_KP_9;
|
||||||
|
case Key::NumpadPlus: return XK_KP_Add;
|
||||||
|
case Key::NumpadMinus: return XK_KP_Subtract;
|
||||||
|
case Key::NumpadMultiply: return XK_KP_Multiply;
|
||||||
|
case Key::NumpadDivide: return XK_KP_Divide;
|
||||||
|
case Key::NumpadEnter: return XK_KP_Enter;
|
||||||
|
case Key::NumpadDecimal: return XK_KP_Decimal;
|
||||||
|
case Key::VolumeMute: return XF86XK_AudioMute;
|
||||||
|
case Key::VolumeUp: return XF86XK_AudioRaiseVolume;
|
||||||
|
case Key::VolumeDown: return XF86XK_AudioLowerVolume;
|
||||||
|
case Key::Calculator: return XF86XK_Calculator;
|
||||||
|
case Key::MediaPlayPause: return XF86XK_AudioPlay;
|
||||||
|
case Key::MediaStop: return XF86XK_AudioStop;
|
||||||
|
case Key::MediaPrevious: return XF86XK_AudioPrev;
|
||||||
|
case Key::MediaNext: return XF86XK_AudioNext;
|
||||||
|
case Key::Application: return XF86XK_ApplicationRight;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
static_assert(static_cast<size_t>(Key::Count) == 147, "update keymap");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
114
xbanan/main.cpp
114
xbanan/main.cpp
@@ -1,10 +1,10 @@
|
|||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "Definitions.h"
|
#include "Definitions.h"
|
||||||
#include "Keymap.h"
|
|
||||||
|
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
CARD32 g_next_global_id { 1 };
|
||||||
|
|
||||||
const xPixmapFormat g_formats[6] {
|
const xPixmapFormat g_formats[6] {
|
||||||
{
|
{
|
||||||
.depth = 1,
|
.depth = 1,
|
||||||
@@ -58,7 +60,7 @@ const xDepth g_depth {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const xVisualType g_visual {
|
const xVisualType g_visual {
|
||||||
.visualID = 1,
|
.visualID = g_next_global_id++,
|
||||||
.c_class = TrueColor,
|
.c_class = TrueColor,
|
||||||
.bitsPerRGB = 8,
|
.bitsPerRGB = 8,
|
||||||
.colormapEntries = 256,
|
.colormapEntries = 256,
|
||||||
@@ -68,24 +70,26 @@ const xVisualType g_visual {
|
|||||||
};
|
};
|
||||||
|
|
||||||
xWindowRoot g_root {
|
xWindowRoot g_root {
|
||||||
.windowId = 2,
|
.windowId = g_next_global_id++,
|
||||||
.defaultColormap = 0,
|
.defaultColormap = 0,
|
||||||
.whitePixel = 0xFFFFFF,
|
.whitePixel = 0xFFFFFF,
|
||||||
.blackPixel = 0x000000,
|
.blackPixel = 0x000000,
|
||||||
.currentInputMask = 0,
|
.currentInputMask = 0,
|
||||||
.pixWidth = 0,
|
.pixWidth = 0,
|
||||||
.pixHeight = 0,
|
.pixHeight = 0,
|
||||||
.mmWidth = 0,
|
.mmWidth = 0,
|
||||||
.mmHeight = 0,
|
.mmHeight = 0,
|
||||||
.minInstalledMaps = 1,
|
.minInstalledMaps = 1,
|
||||||
.maxInstalledMaps = 1,
|
.maxInstalledMaps = 1,
|
||||||
.rootVisualID = g_visual.visualID,
|
.rootVisualID = g_visual.visualID,
|
||||||
.backingStore = 0,
|
.backingStore = 0,
|
||||||
.saveUnders = 0,
|
.saveUnders = 0,
|
||||||
.rootDepth = 24,
|
.rootDepth = g_depth.depth,
|
||||||
.nDepths = 1,
|
.nDepths = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BAN::Vector<DisplayInfo> g_displays;
|
||||||
|
|
||||||
BAN::HashMap<CARD32, BAN::UniqPtr<Object>> g_objects;
|
BAN::HashMap<CARD32, BAN::UniqPtr<Object>> g_objects;
|
||||||
|
|
||||||
BAN::HashMap<BAN::String, ATOM> g_atoms_name_to_id;
|
BAN::HashMap<BAN::String, ATOM> g_atoms_name_to_id;
|
||||||
@@ -99,6 +103,8 @@ int g_server_grabber_fd = -1;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
for (int sig = 1; sig < NSIG; sig++)
|
for (int sig = 1; sig < NSIG; sig++)
|
||||||
if (sig != SIGWINCH)
|
if (sig != SIGWINCH)
|
||||||
signal(sig, exit);
|
signal(sig, exit);
|
||||||
@@ -259,15 +265,53 @@ int main()
|
|||||||
APPEND_ATOM_CUSTOM(_NET_WM_WINDOW_TYPE_UTILITY);
|
APPEND_ATOM_CUSTOM(_NET_WM_WINDOW_TYPE_UTILITY);
|
||||||
#undef APPEND_ATOM_CUSTOM
|
#undef APPEND_ATOM_CUSTOM
|
||||||
|
|
||||||
MUST(initialize_keymap());
|
if (!g_platform_ops.initialize())
|
||||||
|
|
||||||
uint32_t display_w, display_h;
|
|
||||||
if (!g_platform_ops.initialize(&display_w, &display_h))
|
|
||||||
return 1;
|
return 1;
|
||||||
g_root.pixWidth = display_w;
|
|
||||||
g_root.pixHeight = display_h;
|
if (g_displays.empty())
|
||||||
g_root.mmWidth = static_cast<CARD16>(display_w * 254 / 960); // 96 DPI
|
{
|
||||||
g_root.mmHeight = static_cast<CARD16>(display_h * 254 / 960); // 96 DPI
|
dwarnln("No displays windows initilized");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t display_min_x { INT32_MAX }, display_min_y { INT32_MAX };
|
||||||
|
int32_t display_max_x { INT32_MIN }, display_max_y { INT32_MIN };
|
||||||
|
for (const auto& display : g_displays)
|
||||||
|
{
|
||||||
|
display_min_x = BAN::Math::min<int32_t>(display_min_x, display.x);
|
||||||
|
display_min_y = BAN::Math::min<int32_t>(display_min_y, display.y);
|
||||||
|
display_max_x = BAN::Math::max<int32_t>(display_max_x, display.x + display.w);
|
||||||
|
display_max_y = BAN::Math::max<int32_t>(display_max_y, display.y + display.h);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_root.pixWidth = display_max_x - display_min_x;
|
||||||
|
g_root.pixHeight = display_max_y - display_min_y;
|
||||||
|
|
||||||
|
g_root.mmWidth = g_root.pixWidth * 254 / 960; // 96 DPI
|
||||||
|
g_root.mmHeight = g_root.pixHeight * 254 / 960; // 96 DPI
|
||||||
|
|
||||||
|
Client dummy_owner;
|
||||||
|
MUST(g_objects.insert(g_root.windowId, MUST(BAN::UniqPtr<Object>::create(Object {
|
||||||
|
.type = Object::Type::Window,
|
||||||
|
.object = Object::Window {
|
||||||
|
.owner = dummy_owner,
|
||||||
|
.depth = g_root.rootDepth,
|
||||||
|
.x = display_min_x,
|
||||||
|
.y = display_min_y,
|
||||||
|
.parent = None,
|
||||||
|
.cursor = None,
|
||||||
|
.c_class = InputOutput,
|
||||||
|
.width = g_root.pixWidth,
|
||||||
|
.height = g_root.pixHeight,
|
||||||
|
.background = None,
|
||||||
|
}
|
||||||
|
}))));
|
||||||
|
|
||||||
|
MUST(g_objects.insert(g_visual.visualID,
|
||||||
|
MUST(BAN::UniqPtr<Object>::create(Object {
|
||||||
|
.type = Object::Type::Visual,
|
||||||
|
}))
|
||||||
|
));
|
||||||
|
|
||||||
printf("xbanan started\n");
|
printf("xbanan started\n");
|
||||||
|
|
||||||
@@ -353,28 +397,6 @@ int main()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Client dummy_client {};
|
|
||||||
MUST(g_objects.insert(g_root.windowId,
|
|
||||||
MUST(BAN::UniqPtr<Object>::create(Object {
|
|
||||||
.type = Object::Type::Window,
|
|
||||||
.object = Object::Window {
|
|
||||||
.owner = dummy_client,
|
|
||||||
.mapped = true,
|
|
||||||
.depth = g_root.rootDepth,
|
|
||||||
.parent = None,
|
|
||||||
.c_class = InputOutput,
|
|
||||||
.width = g_root.pixWidth,
|
|
||||||
.height = g_root.pixHeight,
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
));
|
|
||||||
|
|
||||||
MUST(g_objects.insert(g_visual.visualID,
|
|
||||||
MUST(BAN::UniqPtr<Object>::create(Object {
|
|
||||||
.type = Object::Type::Visual,
|
|
||||||
}))
|
|
||||||
));
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
epoll_event events[16];
|
epoll_event events[16];
|
||||||
@@ -391,11 +413,21 @@ int main()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BAN::Optional<uint32_t> client_pid;
|
||||||
|
|
||||||
|
#ifdef SO_PEERCRED
|
||||||
|
ucred client_cred;
|
||||||
|
socklen_t client_cred_len = sizeof(client_cred);
|
||||||
|
if (getsockopt(client_sock, SOL_SOCKET, SO_PEERCRED, &client_cred, &client_cred_len) == 0)
|
||||||
|
client_pid = client_cred.pid;
|
||||||
|
#endif
|
||||||
|
|
||||||
MUST(g_epoll_thingies.insert(client_sock, {
|
MUST(g_epoll_thingies.insert(client_sock, {
|
||||||
.type = EpollThingy::Type::Client,
|
.type = EpollThingy::Type::Client,
|
||||||
.value = Client {
|
.value = Client {
|
||||||
.fd = client_sock,
|
.fd = client_sock,
|
||||||
.state = Client::State::ConnectionSetup,
|
.state = Client::State::ConnectionSetup,
|
||||||
|
.pid = client_pid,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -597,6 +629,18 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& [_, object] : g_objects)
|
||||||
|
{
|
||||||
|
if (object->type != Object::Type::Window)
|
||||||
|
continue;
|
||||||
|
auto& window = object->object.get<Object::Window>();
|
||||||
|
if (!window.platform_window_invalidated)
|
||||||
|
continue;
|
||||||
|
if (g_platform_ops.end_frame)
|
||||||
|
g_platform_ops.end_frame(window.platform_window.ptr());
|
||||||
|
window.platform_window_invalidated = false;
|
||||||
|
}
|
||||||
|
|
||||||
iterator_invalidated:
|
iterator_invalidated:
|
||||||
for (auto& [_, thingy] : g_epoll_thingies)
|
for (auto& [_, thingy] : g_epoll_thingies)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user