Use glfw 3.3 functions for the primary selection
Allows us to drop the dependency on xsel for systems with glfw 3.3
This commit is contained in:
parent
9322b210ff
commit
7f3c808e66
@ -85,7 +85,8 @@ the following dependencies are installed first.
|
|||||||
* libpng
|
* libpng
|
||||||
* glew >= 2.0 (not needed on macOS)
|
* glew >= 2.0 (not needed on macOS)
|
||||||
* fontconfig (not needed on macOS)
|
* fontconfig (not needed on macOS)
|
||||||
* xrdb and xsel (only on X11 based systems)
|
* xrdb (only on X11 based systems)
|
||||||
|
* xsel (only on X11 systems with glfw < 3.3)
|
||||||
* ImageMagick (optional, needed to use the `kitty icat` tool to display images in the terminal)
|
* ImageMagick (optional, needed to use the `kitty icat` tool to display images in the terminal)
|
||||||
* gcc or clang (required only for building)
|
* gcc or clang (required only for building)
|
||||||
* pkg-config (required only for building)
|
* pkg-config (required only for building)
|
||||||
|
|||||||
@ -139,6 +139,7 @@ extern bool init_keys(PyObject *module);
|
|||||||
extern bool init_graphics(PyObject *module);
|
extern bool init_graphics(PyObject *module);
|
||||||
extern bool init_shaders(PyObject *module);
|
extern bool init_shaders(PyObject *module);
|
||||||
extern bool init_shaders_debug(PyObject *module);
|
extern bool init_shaders_debug(PyObject *module);
|
||||||
|
extern bool init_x11_funcs(PyObject *module);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
extern int init_CoreText(PyObject *);
|
extern int init_CoreText(PyObject *);
|
||||||
extern bool init_cocoa(PyObject *module);
|
extern bool init_cocoa(PyObject *module);
|
||||||
@ -180,6 +181,7 @@ PyInit_fast_data_types(void) {
|
|||||||
if (!init_Face(m)) return NULL;
|
if (!init_Face(m)) return NULL;
|
||||||
if (!init_freetype_library(m)) return NULL;
|
if (!init_freetype_library(m)) return NULL;
|
||||||
if (!init_fontconfig_library(m)) return NULL;
|
if (!init_fontconfig_library(m)) return NULL;
|
||||||
|
if (!init_x11_funcs(m)) return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OOF(n) #n, offsetof(Cell, n)
|
#define OOF(n) #n, offsetof(Cell, n)
|
||||||
|
|||||||
@ -163,12 +163,14 @@ def parse_color_set(raw):
|
|||||||
def get_primary_selection():
|
def get_primary_selection():
|
||||||
if isosx:
|
if isosx:
|
||||||
return '' # There is no primary selection on OS X
|
return '' # There is no primary selection on OS X
|
||||||
# glfw has no way to get the primary selection
|
try:
|
||||||
# https://github.com/glfw/glfw/issues/894
|
from .fast_data_types import get_selection_x11
|
||||||
ans = subprocess.check_output(['xsel', '-p'], stderr=open(os.devnull, 'wb'), stdin=open(os.devnull, 'rb')).decode('utf-8')
|
ans = (get_selection_x11() or b'').decode('utf-8', 'replace')
|
||||||
if ans:
|
except ImportError:
|
||||||
# Without this for some reason repeated pastes dont work
|
ans = subprocess.check_output(['xsel', '-p'], stderr=open(os.devnull, 'wb'), stdin=open(os.devnull, 'rb')).decode('utf-8')
|
||||||
set_primary_selection(ans)
|
if ans:
|
||||||
|
# Without this for some reason repeated pastes dont work
|
||||||
|
set_primary_selection(ans)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
@ -191,9 +193,13 @@ def set_primary_selection(text):
|
|||||||
return # There is no primary selection on OS X
|
return # There is no primary selection on OS X
|
||||||
if isinstance(text, str):
|
if isinstance(text, str):
|
||||||
text = text.encode('utf-8')
|
text = text.encode('utf-8')
|
||||||
p = subprocess.Popen(['xsel', '-i', '-p'], stdin=subprocess.PIPE, stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
|
try:
|
||||||
p.stdin.write(text), p.stdin.close()
|
from .fast_data_types import set_selection_x11
|
||||||
p.wait()
|
set_selection_x11(text)
|
||||||
|
except ImportError:
|
||||||
|
p = subprocess.Popen(['xsel', '-i', '-p'], stdin=subprocess.PIPE, stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
|
||||||
|
p.stdin.write(text), p.stdin.close()
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
def open_url(url, program='default'):
|
def open_url(url, program='default'):
|
||||||
|
|||||||
49
kitty/x11.c
Normal file
49
kitty/x11.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* x11.c
|
||||||
|
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
*
|
||||||
|
* Distributed under terms of the GPL3 license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR > 2)
|
||||||
|
#define HAS_X11_SELECTION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_X11_SELECTION
|
||||||
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
|
#include <GLFW/glfw3native.h>
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
get_selection_x11(PyObject *self) {
|
||||||
|
(void)(self);
|
||||||
|
return Py_BuildValue("y", glfwGetX11SelectionString());
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
set_selection_x11(PyObject *self, PyObject *args) {
|
||||||
|
(void)(self);
|
||||||
|
const char *data;
|
||||||
|
if (!PyArg_ParseTuple(args, "y", &data)) return NULL;
|
||||||
|
glfwSetX11SelectionString(data);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef sel_methods[] = {
|
||||||
|
{"get_selection_x11", (PyCFunction)get_selection_x11, METH_NOARGS, ""},
|
||||||
|
{"set_selection_x11", (PyCFunction)set_selection_x11, METH_VARARGS, ""},
|
||||||
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool
|
||||||
|
init_x11_funcs(PyObject *module) {
|
||||||
|
#ifdef HAS_X11_SELECTION
|
||||||
|
if (PyModule_AddFunctions(module, sel_methods) != 0) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user