fix: crash when switch session

This commit is contained in:
DreamMaoMao 2025-03-25 20:44:47 +08:00
parent 4c59533fad
commit a032f817b4
2 changed files with 141 additions and 141 deletions

View file

@ -2168,8 +2168,9 @@ cleanupkeyboard(struct wl_listener *listener, void *data) {
free(kb);
}
void // 0.5 custom
cleanupmon(struct wl_listener *listener, void *data) {
void
cleanupmon(struct wl_listener *listener, void *data)
{
Monitor *m = wl_container_of(listener, m, destroy);
LayerSurface *l, *tmp;
size_t i;
@ -2193,7 +2194,8 @@ cleanupmon(struct wl_listener *listener, void *data) {
free(m);
}
void closemon(Monitor *m) // 0.5 custom
void
closemon(Monitor *m)
{
/* update selmon if needed and
* move closed monitor's clients to the focused one */
@ -2205,25 +2207,23 @@ void closemon(Monitor *m) // 0.5 custom
do /* don't switch to disabled mons */
selmon = wl_container_of(mons.next, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
if (!selmon->wlr_output->enabled)
selmon = NULL;
}
wl_list_for_each(c, &clients, link) {
if (c->isfloating && c->geom.x > m->m.width)
resize(c,
(struct wlr_box){.x = c->geom.x - m->w.width,
.y = c->geom.y,
.width = c->geom.width,
.height = c->geom.height},
0);
if (c->mon == m) {
resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y,
.width = c->geom.width, .height = c->geom.height}, 0);
if (c->mon == m)
setmon(c, selmon, c->tags);
reset_foreign_tolevel(c);
}
}
focusclient(focustop(selmon), 1);
printstatus();
}
void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
LayerSurface *l = wl_container_of(listener, l, surface_commit);
struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
@ -6252,8 +6252,9 @@ void unmapnotify(struct wl_listener *listener, void *data) {
motionnotify(0, NULL, 0, 0, 0, 0);
}
void // 0.5 custom
updatemons(struct wl_listener *listener, void *data) {
void
updatemons(struct wl_listener *listener, void *data)
{
/*
* Called whenever the output layout changes: adding or removing a
* monitor, changing an output's mode or position, etc. This is where
@ -6261,8 +6262,8 @@ updatemons(struct wl_listener *listener, void *data) {
* positions, focus, and the stored configuration in wlroots'
* output-manager implementation.
*/
struct wlr_output_configuration_v1 *config =
wlr_output_configuration_v1_create();
struct wlr_output_configuration_v1 *config
= wlr_output_configuration_v1_create();
Client *c;
struct wlr_output_configuration_head_v1 *config_head;
Monitor *m;
@ -6271,8 +6272,7 @@ updatemons(struct wl_listener *listener, void *data) {
wl_list_for_each(m, &mons, link) {
if (m->wlr_output->enabled || m->asleep)
continue;
config_head =
wlr_output_configuration_head_v1_create(config, m->wlr_output);
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
config_head->state.enabled = 0;
/* Remove this output from the layout to avoid cursor enter inside it */
wlr_output_layout_remove(output_layout, m->wlr_output);
@ -6281,14 +6281,17 @@ updatemons(struct wl_listener *listener, void *data) {
}
/* Insert outputs that need to */
wl_list_for_each(m, &mons, link) {
if (m->wlr_output->enabled &&
!wlr_output_layout_get(output_layout, m->wlr_output))
if (m->wlr_output->enabled
&& !wlr_output_layout_get(output_layout, m->wlr_output))
wlr_output_layout_add_auto(output_layout, m->wlr_output);
}
/* Now that we update the output layout we can get its box */
wlr_output_layout_get_box(output_layout, NULL, &sgeom);
// wlr_scene_node_set_position(&root_bg->node, sgeom.x, sgeom.y);
// wlr_scene_rect_set_size(root_bg, sgeom.width, sgeom.height);
/* Make sure the clients are hidden when dwl is locked */
wlr_scene_node_set_position(&locked_bg->node, sgeom.x, sgeom.y);
wlr_scene_rect_set_size(locked_bg, sgeom.width, sgeom.height);
@ -6296,8 +6299,7 @@ updatemons(struct wl_listener *listener, void *data) {
wl_list_for_each(m, &mons, link) {
if (!m->wlr_output->enabled)
continue;
config_head =
wlr_output_configuration_head_v1_create(config, m->wlr_output);
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
/* Get the effective monitor geometry to use for surfaces */
wlr_output_layout_get_box(output_layout, m->wlr_output, &m->m);
@ -6310,14 +6312,13 @@ updatemons(struct wl_listener *listener, void *data) {
if (m->lock_surface) {
struct wlr_scene_tree *scene_tree = m->lock_surface->surface->data;
wlr_scene_node_set_position(&scene_tree->node, m->m.x, m->m.y);
wlr_session_lock_surface_v1_configure(m->lock_surface, m->m.width,
m->m.height);
wlr_session_lock_surface_v1_configure(m->lock_surface, m->m.width, m->m.height);
}
/* Calculate the effective monitor geometry to use for clients */
arrangelayers(m);
/* Don't move clients to the left output when plugging monitors */
arrange(m, false);
arrange(m,false);
/* make sure fullscreen clients have the right size */
if ((c = focustop(m)) && c->isfullscreen)
resize(c, m->m, 0);
@ -6328,6 +6329,7 @@ updatemons(struct wl_listener *listener, void *data) {
config_head->state.x = m->m.x;
config_head->state.y = m->m.y;
if (!selmon) {
selmon = m;
}
@ -6335,10 +6337,8 @@ updatemons(struct wl_listener *listener, void *data) {
if (selmon && selmon->wlr_output->enabled) {
wl_list_for_each(c, &clients, link) {
if (!c->mon && client_surface(c)->mapped) {
if (!c->mon && client_surface(c)->mapped)
setmon(c, selmon, c->tags);
reset_foreign_tolevel(c);
}
}
focusclient(focustop(selmon), 1);
if (selmon->lock_surface) {

View file

@ -29,7 +29,7 @@ double default_mfact = 0.55f; // master 窗口比例
double default_smfact = 0.5f; // 第一个stack窗口比例
unsigned int default_nmaster = 1; // 默认master数量
/* logging */
int log_level = WLR_ERROR;
int log_level = WLR_DEBUG;
unsigned int numlockon = 1; // 是否打开右边小键盘
unsigned int capslock = 0; // 是否启用快捷键