Use X11 loader functions instead of linking to X11 libs

pull/131/head
jackun 4 years ago
parent 71b37906da
commit 2f034c6d1e
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -98,7 +98,7 @@ dep_wayland_client = dependency('wayland-client',
if dep_x11.found()
vulkan_wsi_args += ['-DVK_USE_PLATFORM_XLIB_KHR']
vulkan_wsi_deps += dep_x11
vulkan_wsi_deps += dep_x11.partial_dependency(compile_args : true, includes : true)
endif
if dep_wayland_client.found()
vulkan_wsi_args += ['-DVK_USE_PLATFORM_WAYLAND_KHR']

@ -1,18 +1,23 @@
#include <X11/Xlib.h>
#include <iostream>
#include "X11/keysym.h"
#include <functional>
#pragma once
#include "shared_x11.h"
#include "loaders/loader_x11.h"
#ifndef KeySym
typedef unsigned long KeySym;
#endif
double elapsedF2, elapsedF12, elapsedReloadCfg;
uint64_t last_f2_press, last_f12_press, reload_cfg_press;
pthread_t f2;
char *displayid = getenv("DISPLAY");
std::unique_ptr<Display, std::function<void(Display*)>> dpy(XOpenDisplay(displayid), [](Display* d) { XCloseDisplay(d); });
bool key_is_pressed(KeySym ks) {
if (!init_x11())
return false;
char keys_return[32];
XQueryKeymap(dpy.get(), keys_return);
KeyCode kc2 = XKeysymToKeycode(dpy.get(), ks);
g_x11->XQueryKeymap(get_xdisplay(), keys_return);
KeyCode kc2 = g_x11->XKeysymToKeycode(get_xdisplay(), ks);
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));
return isPressed;
}

@ -61,7 +61,8 @@ opengl_files = files(
'gl/gl3w/GL/gl3w.c',
)
if get_option('with_xnvctrl').enabled()
if get_option('with_x11').enabled() and \
get_option('with_xnvctrl').enabled()
pre_args += '-DHAVE_XNVCTRL'
vklayer_files += files(
'loaders/loader_nvctrl.cpp',
@ -74,6 +75,8 @@ if get_option('with_x11').enabled()
opengl_files += files(
'gl/inject_glx.cpp',
'loaders/loader_glx.cpp',
'loaders/loader_x11.cpp',
'shared_x11.cpp',
)
endif

@ -5,10 +5,10 @@
#include "nvctrl.h"
#include "loaders/loader_nvctrl.h"
#include "string_utils.h"
#include "shared_x11.h"
typedef std::unordered_map<std::string, std::string> string_map;
Display *display = XOpenDisplay(NULL);
libnvctrl_loader nvctrl("libXNVCtrl.so");
struct nvctrlInfo nvctrl_info;
@ -16,8 +16,8 @@ bool nvctrlSuccess = false;
bool checkXNVCtrl()
{
if (nvctrl.IsLoaded()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(display, 0);
if (init_x11() && nvctrl.IsLoaded()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(get_xdisplay(), 0);
if (!nvctrlSuccess)
std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl;
return nvctrlSuccess;
@ -47,7 +47,7 @@ void parse_token(std::string token, string_map& options) {
char* get_attr_target_string(int attr, int target_type, int target_id) {
char* c = nullptr;
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) {
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(get_xdisplay(), target_type, target_id, 0, attr, &c)) {
std::cerr << "Failed to query attribute '" << attr << "'.\n";
}
return c;
@ -57,6 +57,9 @@ void getNvctrlInfo(){
string_map params;
std::string token;
if (!init_x11())
return;
int enums[] = {
NV_CTRL_STRING_GPU_UTILIZATION,
NV_CTRL_STRING_GPU_CURRENT_CLOCK_FREQS,
@ -83,7 +86,7 @@ void getNvctrlInfo(){
nvctrl_info.MemClock = 0;
int64_t temp = 0;
nvctrl.XNVCTRLQueryTargetAttribute64(display,
nvctrl.XNVCTRLQueryTargetAttribute64(get_xdisplay(),
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
@ -92,7 +95,7 @@ void getNvctrlInfo(){
nvctrl_info.temp = temp;
int64_t memtotal = 0;
nvctrl.XNVCTRLQueryTargetAttribute64(display,
nvctrl.XNVCTRLQueryTargetAttribute64(get_xdisplay(),
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
@ -101,11 +104,11 @@ void getNvctrlInfo(){
nvctrl_info.memoryTotal = memtotal;
int64_t memused = 0;
nvctrl.XNVCTRLQueryTargetAttribute64(display,
nvctrl.XNVCTRLQueryTargetAttribute64(get_xdisplay(),
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_USED_DEDICATED_GPU_MEMORY,
&memused);
nvctrl_info.memoryUsed = memused;
}
}

@ -810,13 +810,19 @@ void init_system_info(){
}
void check_keybinds(struct overlay_params& params){
bool pressed = false; // FIXME just a placeholder until wayland support
uint64_t now = os_time_get(); /* us */
elapsedF2 = (double)(now - last_f2_press);
elapsedF12 = (double)(now - last_f12_press);
elapsedReloadCfg = (double)(now - reload_cfg_press);
if (elapsedF2 >= 500000 && !params.output_file.empty()){
if (key_is_pressed(params.toggle_logging)){
#ifdef HAVE_X11
pressed = key_is_pressed(params.toggle_logging);
#else
pressed = false;
#endif
if (pressed){
last_f2_press = now;
log_start = now;
loggingOn = !loggingOn;
@ -828,14 +834,24 @@ void check_keybinds(struct overlay_params& params){
}
if (elapsedF12 >= 500000){
if (key_is_pressed(params.toggle_hud)){
#ifdef HAVE_X11
pressed = key_is_pressed(params.toggle_hud);
#else
pressed = false;
#endif
if (pressed){
last_f12_press = now;
params.no_display = !params.no_display;
}
}
if (elapsedReloadCfg >= 500000){
if (key_is_pressed(params.reload_cfg)){
#ifdef HAVE_X11
pressed = key_is_pressed(params.reload_cfg);
#else
pressed = false;
#endif
if (pressed){
parse_overlay_config(&params, getenv("MANGOHUD_CONFIG"));
reload_cfg_press = now;
}

@ -26,8 +26,6 @@
#include <stdlib.h>
#include <errno.h>
#include <sys/sysinfo.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <wordexp.h>
#include "imgui.h"
#include <iostream>
@ -38,6 +36,11 @@
#include "mesa/util/os_socket.h"
#ifdef HAVE_X11
#include <X11/keysym.h>
#include "loaders/loader_x11.h"
#endif
static enum overlay_param_position
parse_position(const char *str)
@ -86,23 +89,31 @@ parse_alpha(const char *str)
return strtof(str, NULL);
}
#ifdef HAVE_X11
static KeySym
parse_toggle_hud(const char *str)
{
return XStringToKeysym(str);
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
}
static KeySym
parse_toggle_logging(const char *str)
{
return XStringToKeysym(str);
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
}
static KeySym
parse_reload_cfg(const char *str)
{
return XStringToKeysym(str);
if (g_x11->IsLoaded())
return g_x11->XStringToKeysym(str);
return 0;
}
#endif
static uint32_t
parse_fps_sampling_period(const char *str)

Loading…
Cancel
Save