Dont shadow the glfw global mouse state variable

This commit is contained in:
Kovid Goyal 2017-09-25 21:59:33 +05:30
parent af971af4ca
commit 9cfc19e010
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 5 additions and 8 deletions

View File

@ -594,9 +594,8 @@ cm_thread_write(PyObject UNUSED *self, PyObject *args) {
static inline void static inline void
hide_mouse(double now) { hide_mouse(double now) {
if (global_state.mouse_visible && OPT(mouse_hide_wait) > 0 && now - global_state.last_mouse_activity_at > OPT(mouse_hide_wait)) { if (glfwGetInputMode(glfw_window_id, GLFW_CURSOR) == GLFW_CURSOR_NORMAL && OPT(mouse_hide_wait) > 0 && now - global_state.last_mouse_activity_at > OPT(mouse_hide_wait)) {
glfwSetInputMode(glfw_window_id, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetInputMode(glfw_window_id, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
global_state.mouse_visible = false;
} }
} }

View File

@ -74,7 +74,7 @@ key_callback(GLFWwindow UNUSED *w, int key, int scancode, int action, int mods)
static void static void
mouse_button_callback(GLFWwindow *w, int button, int action, int mods) { mouse_button_callback(GLFWwindow *w, int button, int action, int mods) {
if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); }
double now = monotonic(); double now = monotonic();
global_state.last_mouse_activity_at = now; global_state.last_mouse_activity_at = now;
if (button >= 0 && (unsigned int)button < sizeof(global_state.mouse_button_pressed)/sizeof(global_state.mouse_button_pressed[0])) { if (button >= 0 && (unsigned int)button < sizeof(global_state.mouse_button_pressed)/sizeof(global_state.mouse_button_pressed[0])) {
@ -85,7 +85,7 @@ mouse_button_callback(GLFWwindow *w, int button, int action, int mods) {
static void static void
cursor_pos_callback(GLFWwindow *w, double x, double y) { cursor_pos_callback(GLFWwindow *w, double x, double y) {
if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); }
double now = monotonic(); double now = monotonic();
global_state.last_mouse_activity_at = now; global_state.last_mouse_activity_at = now;
global_state.cursor_blink_zero_time = now; global_state.cursor_blink_zero_time = now;
@ -95,7 +95,7 @@ cursor_pos_callback(GLFWwindow *w, double x, double y) {
static void static void
scroll_callback(GLFWwindow *w, double xoffset, double yoffset) { scroll_callback(GLFWwindow *w, double xoffset, double yoffset) {
if (!global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; } if (glfwGetInputMode(w, GLFW_CURSOR) != GLFW_CURSOR_NORMAL) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); }
double now = monotonic(); double now = monotonic();
global_state.last_mouse_activity_at = now; global_state.last_mouse_activity_at = now;
scroll_event(xoffset, yoffset); scroll_event(xoffset, yoffset);
@ -104,7 +104,6 @@ scroll_callback(GLFWwindow *w, double xoffset, double yoffset) {
static void static void
window_focus_callback(GLFWwindow UNUSED *w, int focused) { window_focus_callback(GLFWwindow UNUSED *w, int focused) {
global_state.application_focused = focused ? true : false; global_state.application_focused = focused ? true : false;
if (focused && !global_state.mouse_visible) { glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); global_state.mouse_visible = true; }
double now = monotonic(); double now = monotonic();
global_state.last_mouse_activity_at = now; global_state.last_mouse_activity_at = now;
global_state.cursor_blink_zero_time = now; global_state.cursor_blink_zero_time = now;

View File

@ -287,7 +287,6 @@ init_state(PyObject *module) {
global_state.application_focused = true; global_state.application_focused = true;
global_state.cursor_blink_zero_time = now; global_state.cursor_blink_zero_time = now;
global_state.last_mouse_activity_at = now; global_state.last_mouse_activity_at = now;
global_state.mouse_visible = true;
global_state.cell_width = 1; global_state.cell_height = 1; global_state.cell_width = 1; global_state.cell_height = 1;
if (PyModule_AddFunctions(module, module_methods) != 0) return false; if (PyModule_AddFunctions(module, module_methods) != 0) return false;
return true; return true;

View File

@ -64,7 +64,7 @@ typedef struct {
Tab tabs[MAX_CHILDREN]; Tab tabs[MAX_CHILDREN];
unsigned int active_tab, num_tabs; unsigned int active_tab, num_tabs;
ScreenRenderData tab_bar_render_data; ScreenRenderData tab_bar_render_data;
bool application_focused, mouse_visible; bool application_focused;
double cursor_blink_zero_time, last_mouse_activity_at; double cursor_blink_zero_time, last_mouse_activity_at;
double logical_dpi_x, logical_dpi_y; double logical_dpi_x, logical_dpi_y;
double mouse_x, mouse_y; double mouse_x, mouse_y;