Use the new glfw API for setting WM_CLASS

This commit is contained in:
Kovid Goyal 2017-12-20 09:18:29 +05:30
parent 2f4f3e3331
commit e69de2f968
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 16 additions and 17 deletions

View File

@ -7,7 +7,7 @@ from weakref import WeakValueDictionary
from .cli import create_opts, parse_args
from .config import MINIMUM_FONT_SIZE, cached_values, initial_window_size
from .constants import set_boss, wakeup
from .constants import appname, set_boss, wakeup
from .fast_data_types import (
ChildMonitor, create_os_window, current_os_window, destroy_global_data,
destroy_sprite_map, get_clipboard_string, glfw_post_empty_event,
@ -19,9 +19,8 @@ from .keys import get_shortcut
from .session import create_session
from .tabs import SpecialWindow, TabManager
from .utils import (
encode_wm_class, end_startup_notification, get_primary_selection,
init_startup_notification, open_url, safe_print, set_primary_selection,
single_instance
end_startup_notification, get_primary_selection, init_startup_notification,
open_url, safe_print, set_primary_selection, single_instance
)
@ -82,7 +81,8 @@ class Boss:
def add_os_window(self, startup_session, os_window_id=None, wclass=None, wname=None, size=None, visible=True):
if os_window_id is None:
w, h = initial_window_size(self.opts) if size is None else size
os_window_id = create_os_window(w, h, encode_wm_class(wname or self.args.name, wclass or self.args.cls), visible)
cls = wclass or self.args.cls or appname
os_window_id = create_os_window(w, h, appname, wname or self.args.name or cls, cls, visible)
tm = TabManager(os_window_id, self.opts, self.args, startup_session)
self.os_window_map[os_window_id] = tm
return os_window_id

View File

@ -266,9 +266,9 @@ set_dpi_from_window(OSWindow *w) {
static PyObject*
create_os_window(PyObject UNUSED *self, PyObject *args) {
int width, height, visible = 1, swap_interval = 0, x = -1, y = -1;
char *title;
char *title, *wm_class_class, *wm_class_name;
PyObject *load_programs = NULL;
if (!PyArg_ParseTuple(args, "iis|pOiii", &width, &height, &title, &visible, &load_programs, &swap_interval, &x, &y)) return NULL;
if (!PyArg_ParseTuple(args, "iisss|pOiii", &width, &height, &title, &wm_class_name, &wm_class_class, &visible, &load_programs, &swap_interval, &x, &y)) return NULL;
bool is_first_window = standard_cursor == NULL;
if (is_first_window) {
@ -292,6 +292,11 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
}
}
#ifndef __APPLE__
glfwWindowHintString(GLFW_X11_INSTANCE_NAME, wm_class_name);
glfwWindowHintString(GLFW_X11_CLASS_NAME, wm_class_class);
#endif
if (global_state.num_os_windows >= MAX_CHILDREN) {
PyErr_SetString(PyExc_ValueError, "Too many windows");
return NULL;

View File

@ -12,15 +12,15 @@ from .borders import load_borders_program
from .boss import Boss
from .cli import create_opts, parse_args
from .config import initial_window_size, load_cached_values, save_cached_values
from .constants import glfw_path, is_macos, is_wayland, logo_data_file
from .constants import appname, glfw_path, is_macos, is_wayland, logo_data_file
from .fast_data_types import (
change_wcwidth, create_os_window, glfw_init, glfw_terminate,
install_sigchld_handler, set_default_window_icon, set_options, show_window
)
from .fonts.box_drawing import set_scale
from .utils import (
detach, encode_wm_class, end_startup_notification,
init_startup_notification, single_instance
detach, end_startup_notification, init_startup_notification,
single_instance
)
from .window import load_shader_programs
@ -42,7 +42,7 @@ def run_app(opts, args):
set_options(opts, is_wayland, args.debug_gl)
load_cached_values()
w, h = initial_window_size(opts)
window_id = create_os_window(w, h, encode_wm_class(args.name, args.cls), False, load_all_shaders)
window_id = create_os_window(w, h, appname, args.name or args.cls or appname, args.cls or appname, False, load_all_shaders)
startup_ctx = init_startup_notification(window_id)
show_window(window_id)
if not is_wayland and not is_macos: # no window icons on wayland

View File

@ -264,9 +264,3 @@ def single_instance(group_id=None):
s.set_inheritable(False)
atexit.register(remove_socket_file, s)
return True
def encode_wm_class(name, cls, title=appname):
if is_macos:
return title
return '\x01' + (name or cls) + '\x1e' + cls + '\x1e' + title