Finish single_instance implementation
This commit is contained in:
parent
7deb68de61
commit
96483a0e92
@ -5,6 +5,7 @@
|
||||
from gettext import gettext as _
|
||||
from weakref import WeakValueDictionary
|
||||
|
||||
from .cli import create_opts, option_parser
|
||||
from .config import MINIMUM_FONT_SIZE, cached_values, initial_window_size
|
||||
from .constants import set_boss, wakeup
|
||||
from .fast_data_types import (
|
||||
@ -96,8 +97,13 @@ class Boss:
|
||||
def peer_msg_received(self, msg):
|
||||
import json
|
||||
msg = json.loads(msg.decode('utf-8'))
|
||||
if msg.get('cmd') == 'new_instance':
|
||||
print(msg['args'])
|
||||
if isinstance(msg, dict) and msg.get('cmd') == 'new_instance':
|
||||
args = option_parser().parse_args(msg['args'][1:])
|
||||
opts = create_opts(args)
|
||||
session = create_session(opts, args)
|
||||
self.add_os_window(session)
|
||||
else:
|
||||
safe_print('Unknown message received from peer, ignoring')
|
||||
|
||||
def on_child_death(self, window_id):
|
||||
window = self.window_id_map.pop(window_id, None)
|
||||
|
||||
@ -329,6 +329,7 @@ parse_input(ChildMonitor *self) {
|
||||
// Parse all available input that was read in the I/O thread.
|
||||
size_t count = 0, remove_count = 0;
|
||||
double now = monotonic();
|
||||
PyObject *msg = NULL;
|
||||
children_mutex(lock);
|
||||
while (remove_queue_count) {
|
||||
remove_queue_count--;
|
||||
@ -340,7 +341,7 @@ parse_input(ChildMonitor *self) {
|
||||
if (UNLIKELY(self->messages_count)) {
|
||||
while(self->messages_count) {
|
||||
Message *m = self->messages + --self->messages_count;
|
||||
call_boss(peer_msg_received, "y#", m->data, m->sz);
|
||||
msg = PyBytes_FromStringAndSize(m->data, m->sz);
|
||||
free(m->data); m->data = NULL; m->sz = 0;
|
||||
}
|
||||
}
|
||||
@ -355,6 +356,10 @@ parse_input(ChildMonitor *self) {
|
||||
}
|
||||
}
|
||||
children_mutex(unlock);
|
||||
if (msg) {
|
||||
call_boss(peer_msg_received, "O", msg);
|
||||
Py_CLEAR(msg);
|
||||
}
|
||||
|
||||
while(remove_count) {
|
||||
// must be done while no locks are held, since the locks are non-recursive and
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
import argparse
|
||||
from gettext import gettext as _
|
||||
|
||||
from .config import load_config
|
||||
from .constants import appname, str_version, isosx, defconf
|
||||
from .layout import all_layouts
|
||||
|
||||
@ -131,3 +132,10 @@ def option_parser():
|
||||
)
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def create_opts(args):
|
||||
config = args.config or (defconf, )
|
||||
overrides = (a.replace('=', ' ', 1) for a in args.override or ())
|
||||
opts = load_config(*config, overrides=overrides)
|
||||
return opts
|
||||
|
||||
@ -10,11 +10,9 @@ from contextlib import contextmanager
|
||||
|
||||
from .borders import load_borders_program
|
||||
from .boss import Boss
|
||||
from .cli import option_parser
|
||||
from .config import (
|
||||
initial_window_size, load_cached_values, load_config, save_cached_values
|
||||
)
|
||||
from .constants import defconf, isosx, iswayland, logo_data_file
|
||||
from .cli import create_opts, option_parser
|
||||
from .config import initial_window_size, load_cached_values, save_cached_values
|
||||
from .constants import isosx, iswayland, logo_data_file
|
||||
from .fast_data_types import (
|
||||
change_wcwidth, create_os_window, glfw_init, glfw_init_hint_string,
|
||||
glfw_terminate, install_sigchld_handler, set_default_window_icon,
|
||||
@ -137,9 +135,7 @@ def main():
|
||||
data = json.dumps(data, ensure_ascii=False).encode('utf-8')
|
||||
single_instance.socket.sendall(data)
|
||||
return
|
||||
config = args.config or (defconf, )
|
||||
overrides = (a.replace('=', ' ', 1) for a in args.override or ())
|
||||
opts = load_config(*config, overrides=overrides)
|
||||
opts = create_opts(args)
|
||||
change_wcwidth(not opts.use_system_wcwidth)
|
||||
if GLFW_X11_WM_CLASS_CLASS is not None:
|
||||
glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, args.cls)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user