From 9c44243a301e6eccd6f7b9789a7e40f833e903d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 29 Nov 2016 20:28:09 +0530 Subject: [PATCH] Change the default mouse cursor to the beam cursor --- kitty/glfw.c | 15 +++++++++++++++ kitty/tabs.py | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index 45f46b0d3..7baae141a 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -28,7 +28,10 @@ typedef struct { GLFWwindow *window; PyObject *framebuffer_size_callback, *char_mods_callback, *key_callback, *mouse_button_callback, *scroll_callback, *cursor_pos_callback, *window_focus_callback; + GLFWcursor *standard_cursor, *click_cursor; } Window; + +// callbacks {{{ static Window* window_weakrefs[MAX_WINDOWS] = {0}; static inline Window* @@ -74,6 +77,7 @@ static void window_focus_callback(GLFWwindow *w, int focused) { WINDOW_CALLBACK(window_focus_callback, "O", focused ? Py_True : Py_False); } +// }}} static PyObject* new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { @@ -90,6 +94,9 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { if (window_weakrefs[i] == NULL) { window_weakrefs[i] = self; break; } } if (i >= MAX_WINDOWS) { Py_CLEAR(self); PyErr_SetString(PyExc_ValueError, "Too many windows created"); return NULL; } + self->standard_cursor = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); + self->click_cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR); + if (self->standard_cursor == NULL || self->click_cursor == NULL) { Py_CLEAR(self); PyErr_SetString(PyExc_ValueError, "Failed to create standard mouse cursors"); return NULL; } glfwSetFramebufferSizeCallback(self->window, framebuffer_size_callback); glfwSetCharModsCallback(self->window, char_mods_callback); glfwSetKeyCallback(self->window, key_callback); @@ -228,6 +235,13 @@ is_key_pressed(Window *self, PyObject *args) { return ans; } +static PyObject* +set_click_cursor(Window *self, PyObject *args) { + int c; + if (!PyArg_ParseTuple(args, "p", &c)) return NULL; + glfwSetCursor(self->window, c ? self->click_cursor : self->standard_cursor); + Py_RETURN_NONE; +} static PyObject* _set_title(Window *self, PyObject *args) { @@ -246,6 +260,7 @@ static PyMethodDef methods[] = { MND(should_close, METH_NOARGS), MND(set_should_close, METH_VARARGS), MND(is_key_pressed, METH_VARARGS), + MND(set_click_cursor, METH_VARARGS), MND(make_context_current, METH_NOARGS), {"set_title", (PyCFunction)_set_title, METH_VARARGS, ""}, {NULL} /* Sentinel */ diff --git a/kitty/tabs.py b/kitty/tabs.py index 94268fa19..513647285 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -138,9 +138,7 @@ class TabManager(Thread): glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.sprites.do_layout(cell_size.width, cell_size.height) self.queue_action(self.active_tab.new_window, False) - # self.standard_cursor = glfw.glfwCreateStandardCursor(GLFW_IBEAM_CURSOR) - # self.click_cursor = glfw.glfwCreateStandardCursor(GLFW_HAND_CURSOR) - # glfw.glfwSetCursor(self.glfw_window, self.standard_cursor) + self.glfw_window.set_click_cursor(False) def signal_received(self): try: