diff --git a/glfw/wl_window.c b/glfw/wl_window.c index d75eba810..8aaa94499 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1057,7 +1057,8 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) int _glfwPlatformWindowBell(_GLFWwindow* window) { // TODO: Use an actual Wayland API to implement this when one becomes available - int fd = open("/dev/tty", O_WRONLY | O_CLOEXEC); + static char tty[L_ctermid + 1]; + int fd = open(ctermid(tty), O_WRONLY | O_CLOEXEC); if (fd > -1) { int ret = write(fd, "\x07", 1) == 1 ? GLFW_TRUE : GLFW_FALSE; close(fd); diff --git a/kittens/clipboard/main.py b/kittens/clipboard/main.py index 9dd892005..76f26ea13 100644 --- a/kittens/clipboard/main.py +++ b/kittens/clipboard/main.py @@ -2,7 +2,9 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal +import os import sys + from kitty.cli import parse_args from ..tui.handler import Handler @@ -62,7 +64,7 @@ def main(args): data = None if not sys.stdin.isatty(): data = sys.stdin.buffer.read() - sys.stdin = open('/dev/tty', 'r') + sys.stdin = open(os.ctermid(), 'r') loop = Loop() handler = Clipboard(data, args) loop.loop(handler) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 947eca4fd..7c60cecbd 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -381,7 +381,7 @@ def main(args): return else: text = sys.stdin.buffer.read().decode('utf-8') - sys.stdin = open('/dev/tty') + sys.stdin = open(os.ctermid()) try: args, items = parse_hints_args(args[1:]) except SystemExit as e: diff --git a/kittens/icat/main.py b/kittens/icat/main.py index 66ef41423..2a082c03a 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -260,13 +260,13 @@ def main(args=sys.argv): if args.print_window_size: screen_size_function.ans = None - with open('/dev/tty') as tty: + with open(os.ctermid()) as tty: ss = screen_size_function(tty)() print('{}x{}'.format(ss.width, ss.height), end='') raise SystemExit(0) if not sys.stdout.isatty(): - sys.stdout = open('/dev/tty', 'w') + sys.stdout = open(os.ctermid(), 'w') screen_size = screen_size_function() signal.signal(signal.SIGWINCH, lambda signum, frame: setattr(screen_size, 'changed', True)) if screen_size().width == 0: diff --git a/kittens/show_error/main.py b/kittens/show_error/main.py index 200c883c9..7a75dd6ae 100644 --- a/kittens/show_error/main.py +++ b/kittens/show_error/main.py @@ -2,11 +2,12 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal +import os import sys from kitty.cli import parse_args -from ..tui.operations import styled +from ..tui.operations import styled OPTIONS = '''\ --title @@ -17,7 +18,7 @@ The title for the error message. def real_main(args): error_message = sys.stdin.buffer.read().decode('utf-8') - sys.stdin = open('/dev/tty') + sys.stdin = open(os.ctermid()) msg = 'Show an error message' args, items = parse_args(args, OPTIONS, '', msg, 'hints') print(styled(args.title, fg_intense=True, fg='red', bold=True)) diff --git a/kitty/data-types.c b/kitty/data-types.c index 2b4c96d09..92bad6761 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef WITH_PROFILER #include #endif @@ -123,7 +124,8 @@ open_tty(PyObject *self UNUSED, PyObject *args) { if (!PyArg_ParseTuple(args, "|p", &read_with_timeout)) return NULL; int flags = O_RDWR | O_CLOEXEC | O_NOCTTY; if (!read_with_timeout) flags |= O_NONBLOCK; - int fd = open("/dev/tty", flags); + static char ctty[L_ctermid+1]; + int fd = open(ctermid(ctty), flags); struct termios *termios_p = calloc(1, sizeof(struct termios)); if (!termios_p) return PyErr_NoMemory(); if (tcgetattr(fd, termios_p) != 0) { free(termios_p); PyErr_SetFromErrno(PyExc_OSError); return NULL; }