WIP focus loss fps limiter
parent
05133ae3cd
commit
1df2d0f071
@ -0,0 +1,94 @@
|
|||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include "wsi_helpers.h"
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
|
||||||
|
static bool check_window_focus(xcb_connection_t * connection, xcb_window_t window)
|
||||||
|
{
|
||||||
|
auto reply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
|
||||||
|
if (reply)
|
||||||
|
{
|
||||||
|
SPDLOG_DEBUG("Window: {:08x} Focus WId: {:08x}", window, reply->focus);
|
||||||
|
bool has_focus = (window == reply->focus);
|
||||||
|
free(reply);
|
||||||
|
return has_focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
// xcb_query_tree_cookie_t cookie = xcb_query_tree(connection, reply->focus);
|
||||||
|
// xcb_query_tree_reply_t *tree_reply = nullptr;
|
||||||
|
//
|
||||||
|
// if ((tree_reply = xcb_query_tree_reply(connection, cookie, nullptr))) {
|
||||||
|
// printf("root = 0x%08x\n", tree_reply->root);
|
||||||
|
// printf("parent = 0x%08x\n", tree_reply->parent);
|
||||||
|
//
|
||||||
|
// xcb_window_t *children = xcb_query_tree_children(tree_reply);
|
||||||
|
// for (int i = 0; i < xcb_query_tree_children_length(tree_reply); i++)
|
||||||
|
// printf("child window = 0x%08x\n", children[i]);
|
||||||
|
//
|
||||||
|
// free(reply);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
static bool check_window_focus(Display *disp, Window window)
|
||||||
|
{
|
||||||
|
if (!g_x11 || !g_x11->IsLoaded())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Window focus;
|
||||||
|
int revert_to;
|
||||||
|
|
||||||
|
if (!g_x11->XGetInputFocus(disp, &focus, &revert_to))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
SPDLOG_DEBUG("Window: {:08x}, Focus: {:08x}", window, focus);
|
||||||
|
|
||||||
|
// wine vulkan surface's window is a child of "main" window?
|
||||||
|
Window w = window;
|
||||||
|
Window parent = window;
|
||||||
|
Window root = None;
|
||||||
|
Window *children;
|
||||||
|
unsigned int nchildren;
|
||||||
|
Status s;
|
||||||
|
|
||||||
|
while (parent != root) {
|
||||||
|
w = parent;
|
||||||
|
s = g_x11->XQueryTree(disp, w, &root, &parent, &children, &nchildren);
|
||||||
|
|
||||||
|
if (s)
|
||||||
|
g_x11->XFree(children);
|
||||||
|
|
||||||
|
if (w == focus || !root)
|
||||||
|
{
|
||||||
|
SPDLOG_DEBUG("we got focus");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_DEBUG(" get parent: window: {:08x}, parent: {:08x}, root: {:08x}", w, parent, root);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_DEBUG("parent: {:08x}, focus: {:08x}", w, focus);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool window_has_focus(const wsi_connection* conn)
|
||||||
|
{
|
||||||
|
if (!conn)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
if (conn->xcb.conn)
|
||||||
|
return 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);
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
#include "loaders/loader_x11.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
#include <xcb/xproto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
#include <wayland-client.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct wsi_connection
|
||||||
|
{
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
struct xcb {
|
||||||
|
xcb_connection_t *conn = nullptr;
|
||||||
|
xcb_window_t window = 0;
|
||||||
|
} xcb;
|
||||||
|
#endif
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
struct xlib {
|
||||||
|
Display *dpy = nullptr;
|
||||||
|
Window window = 0;
|
||||||
|
int evmask = 0;
|
||||||
|
} xlib;
|
||||||
|
#endif
|
||||||
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
struct wl {
|
||||||
|
wl_display *display;
|
||||||
|
wl_surface *surface;
|
||||||
|
bool has_focus;
|
||||||
|
} wl;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
// struct wsi_connection;
|
||||||
|
// bool check_window_focus(const wsi_connection&);
|
Loading…
Reference in New Issue