wip wayland

focus_loss
jackun 2 years ago
parent 1df2d0f071
commit c68c48c02f
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -69,6 +69,10 @@ overlay_params params {};
static std::unique_ptr<notify_thread, std::function<void(notify_thread *)>>
stop_it(&notifier, [](notify_thread *n){ stop_notifier(*n); });
static void focus_changed(bool b) {
sw_stats.lost_focus = !b;
};
void imgui_init()
{
if (cfg_inited)
@ -166,6 +170,7 @@ void imgui_create(void *ctx)
create_fonts(params, sw_stats.font1, sw_stats.font_text);
sw_stats.font_params_hash = params.font_params_hash;
wsi_conn.focus_changed = focus_changed;
// Restore global context or ours might clash with apps that use Dear ImGui
ImGui::SetCurrentContext(saved_ctx);

@ -2,6 +2,7 @@
#include "timing.hpp"
#include "logging.h"
#include "keybinds.h"
#include <wayland-client.h>
void check_keybinds(struct overlay_params& params, uint32_t vendorID){
using namespace std::chrono_literals;

@ -43,6 +43,7 @@ endforeach
# files not to be included with mangoapp etc.
vklayer_files_only = files(
'vulkan.cpp',
'wsi_helpers.cpp',
)
@ -56,7 +57,6 @@ vklayer_files = files(
'logging.cpp',
'config.cpp',
'gpu.cpp',
'vulkan.cpp',
'blacklist.cpp',
'file_utils.cpp',
'amdgpu.cpp',

@ -251,7 +251,7 @@ void update_hud_info_with_frametime(struct swapchain_stats& sw_stats, const stru
hw_update_thread->update(&params, vendorID);
#ifndef MANGOAPP
sw_stats.lost_focus = !window_has_focus(sw_stats.wsi);
window_has_focus(sw_stats.wsi);
SPDLOG_DEBUG("lost focus: {}", sw_stats.lost_focus);
#endif

@ -124,6 +124,6 @@ extern void process_control_socket(int& control_client, overlay_params &params);
void render_mpris_metadata(const overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing);
#endif
void update_fan();
bool window_has_focus(const wsi_connection*);
void window_has_focus(wsi_connection*);
#endif //MANGOHUD_OVERLAY_H

@ -65,7 +65,6 @@ namespace MangoHud { namespace GL {
struct surface_data {
VkSurfaceKHR surface;
bool changed_flags;
wsi_connection wsi;
};
@ -454,6 +453,7 @@ static VkResult overlay_CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSu
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
extern void wayland_init(wsi_connection&);
static VkResult overlay_CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
{
SPDLOG_DEBUG("{}", __func__);
@ -464,6 +464,7 @@ static VkResult overlay_CreateWaylandSurfaceKHR(VkInstance instance, const VkWay
struct surface_data *data = new_surface_data(*pSurface);
data->wsi.wl.display = pCreateInfo->display;
data->wsi.wl.surface = pCreateInfo->surface;
wayland_init(data->wsi);
}
return result;
}
@ -1384,6 +1385,9 @@ static void setup_swapchain_data(struct swapchain_data *data,
{
struct device_data *device_data = data->device;
struct surface_data *surface_data = FIND(struct surface_data, pCreateInfo->surface);
surface_data->wsi.focus_changed = [data](bool b) {
data->sw_stats.lost_focus = !b;
};
data->surface_data = surface_data;
data->width = pCreateInfo->imageExtent.width;
data->height = pCreateInfo->imageExtent.height;

@ -76,19 +76,87 @@ static bool check_window_focus(Display *disp, Window window)
}
#endif
bool window_has_focus(const wsi_connection* conn)
void window_has_focus(wsi_connection* conn)
{
if (!conn)
return true;
if (!conn || !conn->focus_changed)
return;
#ifdef VK_USE_PLATFORM_XCB_KHR
if (conn->xcb.conn)
return check_window_focus(conn->xcb.conn, conn->xcb.window);
conn->focus_changed(check_window_focus(conn->xcb.conn, conn->xcb.window));
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
if (conn->xlib.dpy)
return check_window_focus(conn->xlib.dpy, conn->xlib.window);
conn->focus_changed(check_window_focus(conn->xlib.dpy, conn->xlib.window));
#endif
return true;
}
struct interfaces_
{
wl_shell *shell;
wl_seat *seat;
wsi_connection *wsi;
};
static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) {
SPDLOG_DEBUG("{}", __func__);
}
static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
SPDLOG_DEBUG("{}", __func__);
auto wsi = reinterpret_cast<wsi_connection*>(data);
if (wsi->focus_changed && surface == wsi->wl.surface)
wsi->focus_changed(true);
}
static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
SPDLOG_DEBUG("{}", __func__);
auto wsi = reinterpret_cast<wsi_connection*>(data);
if (wsi->focus_changed && surface == wsi->wl.surface)
wsi->focus_changed(false);
}
static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
SPDLOG_DEBUG("{}: key pressed: {}", __func__, key);
}
static void keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
SPDLOG_DEBUG("{}", __func__);
}
static struct wl_keyboard_listener keyboard_listener = {&keyboard_keymap, &keyboard_enter, &keyboard_leave, &keyboard_key, &keyboard_modifiers};
static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) {
SPDLOG_DEBUG("{}", __func__);
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
SPDLOG_DEBUG("SEAT");
struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
wl_keyboard_add_listener (keyboard, &keyboard_listener, data);
}
}
static struct wl_seat_listener seat_listener = {&seat_capabilities};
static void registry_add_object (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
SPDLOG_DEBUG("{}", __func__);
if (!strcmp(interface,"wl_seat")) {
//input_reader* ir = wl_registry_get_user_data(registry);
auto seat = (wl_seat*)wl_registry_bind (registry, name, &wl_seat_interface, 1);
// SPDLOG_DEBUG("wl_seat_add_listener {}", wl_proxy_get_listener((wl_proxy*)seat));
wl_seat_add_listener (seat, &seat_listener, data);
}
}
static void registry_remove_object (void *data, struct wl_registry *registry, uint32_t name) {
}
static struct wl_registry_listener registry_listener = {&registry_add_object, &registry_remove_object};
// interfaces_ g_interfaces {};
void wayland_init(wsi_connection& conn)
{
auto registry = wl_display_get_registry(conn.wl.display);
wl_registry_add_listener(registry, &registry_listener, &conn);
wl_display_roundtrip(conn.wl.display);
}

@ -1,4 +1,5 @@
#pragma once
#include <functional>
#ifdef VK_USE_PLATFORM_XLIB_KHR
#include "loaders/loader_x11.h"
#endif
@ -14,6 +15,8 @@
struct wsi_connection
{
std::function<void(bool)> focus_changed;
#ifdef VK_USE_PLATFORM_XCB_KHR
struct xcb {
xcb_connection_t *conn = nullptr;

Loading…
Cancel
Save