Skip to content

Commit

Permalink
x11: don't do silly content scale games
Browse files Browse the repository at this point in the history
god fucking damnit wayland! aaaaaaaahh!!
  • Loading branch information
hanatos committed Nov 3, 2024
1 parent d1009f1 commit ce0cce7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dt_gui_win_init(dt_gui_win_t *win)
int wd = 3*mode->width/4;
int ht = 3*mode->height/4;
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
// glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
// glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); // this is for github's super ancient ubuntu glfw 3.3
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
Expand Down Expand Up @@ -128,6 +128,8 @@ int dt_gui_init()
{
memset(&vkdt, 0, sizeof(vkdt));
vkdt.graph_res = -1;
const char *is_x11 = getenv("XDG_SESSION_TYPE");
if(!strcmp(is_x11, "x11")) vkdt.is_x11 = 1;
if(!glfwInit())
{
const char* description;
Expand Down
14 changes: 14 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vulkan/vulkan.h>
#include <math.h>
#include <GLFW/glfw3.h>

// max images in flight in vulkan pipeline/swap chain
#define DT_GUI_MAX_IMAGES 8
Expand Down Expand Up @@ -184,6 +185,8 @@ typedef struct dt_gui_t
// list of recently used tags
int tag_cnt;
char tag[10][30];

int is_x11; // running on xorg
}
dt_gui_t;

Expand Down Expand Up @@ -240,6 +243,17 @@ void dt_gui_win1_open();
// close secondary window
void dt_gui_win1_close();

static inline void
dt_gui_content_scale(GLFWwindow *w, float *x, float *y)
{
if(vkdt.is_x11)
{
x[0] = y[0] = 1.0;
return;
}
glfwGetWindowContentScale(w, x, y);
}

// some gui colour things. we want perceptually uniform colour picking.
// since hsv is a severely broken concept, we mean oklab LCh (or hCL really)
static inline void rec2020_to_oklab(const float rgb[], float oklab[])
Expand Down
6 changes: 3 additions & 3 deletions src/gui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static void
mouse_position_callback(GLFWwindow* window, double x, double y)
{
float xscale, yscale;
glfwGetWindowContentScale(window, &xscale, &yscale);
dt_gui_content_scale(window, &xscale, &yscale);
dt_view_mouse_position(window, x*xscale, y*yscale);
}

Expand All @@ -179,7 +179,7 @@ static void
scroll_callback(GLFWwindow *window, double xoff, double yoff)
{
float xscale, yscale;
glfwGetWindowContentScale(window, &xscale, &yscale);
dt_gui_content_scale(window, &xscale, &yscale);
xoff *= xscale;
yoff *= yscale;
dt_view_mouse_scrolled(window, xoff, yoff);
Expand All @@ -192,7 +192,7 @@ static void
pentablet_data_callback(double x, double y, double z, double pressure, double pitch, double yaw, double roll)
{
float xscale, yscale;
glfwGetWindowContentScale(vkdt.win.window, &xscale, &yscale);
dt_gui_content_scale(vkdt.win.window, &xscale, &yscale);
x *= xscale; y *= yscale;
dt_view_pentablet_data(x, y, z, pressure, pitch, yaw, roll);
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/nuklear_glfw_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifdef NK_GLFW_VULKAN_IMPLEMENTATION
#include "shd.h"
#include "qvk/qvk.h"
#include "gui/gui.h"
#endif

#include <assert.h>
Expand Down Expand Up @@ -982,7 +983,7 @@ NK_API void nk_glfw3_new_frame(struct nk_context *ctx, GLFWwindow *window)

glfwGetCursorPos(win->win, &x, &y);
float xscale = 1.0f, yscale = 1.0f;
glfwGetWindowContentScale(win->win, &xscale, &yscale);
dt_gui_content_scale(win->win, &xscale, &yscale);
x *= xscale; y *= yscale;
nk_input_motion(ctx, (int)x, (int)y);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
Expand Down Expand Up @@ -1320,7 +1321,7 @@ nk_glfw3_mouse_button_callback(
return;
glfwGetCursorPos(w, &x, &y);
float xscale, yscale;
glfwGetWindowContentScale(w, &xscale, &yscale);
dt_gui_content_scale(w, &xscale, &yscale);
x *= xscale; y *= yscale;
if (action == GLFW_PRESS) {
double dt = glfwGetTime() - win->last_button_click;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void dt_view_get_cursor_pos(GLFWwindow *window, double *x, double *y)
{
glfwGetCursorPos(window, x, y);
float xscale, yscale;
glfwGetWindowContentScale(window, &xscale, &yscale);
dt_gui_content_scale(window, &xscale, &yscale);
*x *= xscale;
*y *= yscale;
}

0 comments on commit ce0cce7

Please sign in to comment.