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

View file

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