Skip to content

Commit

Permalink
FvwmPager: Clean up DeskStyle initialization.
Browse files Browse the repository at this point in the history
* Initialize new DeskStyle GC's when they are created. There is a dummy
  window available at this time for this, no need to wait.
* Don't put fonts in DeskStyle GC's, fonts are done with FwinString, which
  doesn't use these GCs.
* Fix a typo in the balloon colorset initialization, which would cause
  a crash trying to access a non allocated colorset. This fixes #1014.
* Protect against updating gc's on default desk on colorset change, but
  colorset Pixels still need updated.
* Fix some issues with updating on new_page and new_desk changes.
  • Loading branch information
somiaj authored and ThomasAdam committed Apr 28, 2024
1 parent 9f37323 commit 0ca76da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
1 change: 1 addition & 0 deletions modules/FvwmPager/FvwmPager.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ DeskStyle *FindDeskStyle(int desk)

style->desk = desk;
xasprintf(&style->label, "Desk %d", desk);
initialize_desk_style_gcs(style);

TAILQ_INSERT_TAIL(&desk_style_q, style, entry);
return style;
Expand Down
31 changes: 10 additions & 21 deletions modules/FvwmPager/init_pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ void init_fvwm_pager(void)
initialize_transient();
initialize_pager_window();

/* Initialize DeskStyle GCs */
/* Update styles with user configurations. */
TAILQ_FOREACH(style, &desk_style_q, entry) {
update_desk_style_gcs(style);
}
/* Initialize any non configured desks. */
for (i = 0; i < ndesks; i++) {
/* Create any missing DeskStyles. */
style = FindDeskStyle(i);
}
TAILQ_FOREACH(style, &desk_style_q, entry) {
initialize_desk_style_gcs(style);
}

/* After DeskStyles are initialized, initialize desk windows. */
for (i = 0; i < ndesks; i++) {
Expand Down Expand Up @@ -201,7 +201,7 @@ void initialize_colorset(DeskStyle *style)
}
if (style->balloon_cs >= 0) {
style->balloon_fg = Colorset[style->balloon_cs].fg;
style->balloon_bg = Colorset[style->balloon_bg].bg;
style->balloon_bg = Colorset[style->balloon_cs].bg;
}
}

Expand Down Expand Up @@ -531,14 +531,8 @@ void initialize_desk_style_gcs(DeskStyle *style)

/* Desk labels GC. */
gcv.foreground = style->fg;
if (Scr.Ffont && Scr.Ffont->font) {
gcv.font = Scr.Ffont->font->fid;
style->label_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground | GCFont, &gcv);
} else {
style->label_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground, &gcv);
}
style->label_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground, &gcv);

/* Hilight GC, used for monitors and labels backgrounds. */
gcv.foreground = (Pdepth < 2) ? style->bg : style->hi_bg;
Expand All @@ -547,12 +541,8 @@ void initialize_desk_style_gcs(DeskStyle *style)

/* create the hilight desk title drawing GC */
gcv.foreground = (Pdepth < 2) ? style->fg : style->hi_fg;
if (Scr.Ffont && Scr.Ffont->font)
style->hi_fg_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground | GCFont, &gcv);
else
style->hi_fg_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground, &gcv);
style->hi_fg_gc = fvwmlib_XCreateGC(
dpy, Scr.pager_w, GCForeground, &gcv);

/* create the virtual page boundary GC */
gcv.foreground = style->fg;
Expand Down Expand Up @@ -864,7 +854,6 @@ void parse_options(void)
char *next;

token = PeekToken(tline, &next);

/* Step 1: Initial configuration broadcasts are parsed here. */
if (token[0] == '*') {
/* Module configuration item, skip to next step. */
Expand Down
41 changes: 20 additions & 21 deletions modules/FvwmPager/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ void process_message(FvwmPacket *packet)
switch (type)
{
case M_ADD_WINDOW:
process_configure(body);
break;
case M_CONFIGURE_WINDOW:
process_configure(body);
break;
Expand Down Expand Up @@ -366,7 +364,8 @@ void process_new_page(unsigned long *body)
fp = fpmonitor_this(m);
if (fp == NULL)
return;
do_reconfigure = true;
if (monitor_to_track == NULL)
do_reconfigure = true;
}

fp->virtual_scr.Vx = fp->m->virtual_scr.Vx = body[0];
Expand All @@ -377,16 +376,20 @@ void process_new_page(unsigned long *body)
body[1] = mon_num;
process_new_desk(body);
}
if (fp->virtual_scr.VxPages != body[5] || fp->virtual_scr.VyPages != body[6])
if (fp->virtual_scr.VxPages != body[5] ||
fp->virtual_scr.VyPages != body[6])
{
fp->virtual_scr.VxPages = body[5];
fp->virtual_scr.VyPages = body[6];
fp->virtual_scr.VWidth = fp->virtual_scr.VxPages * fpmonitor_get_all_widths();
fp->virtual_scr.VHeight = fp->virtual_scr.VyPages * fpmonitor_get_all_heights();
fp->virtual_scr.VxMax = fp->virtual_scr.VWidth - fpmonitor_get_all_widths();
fp->virtual_scr.VyMax = fp->virtual_scr.VHeight - fpmonitor_get_all_heights();
if (do_reconfigure)
ReConfigure();
fp->virtual_scr.VWidth =
fp->virtual_scr.VxPages * fpmonitor_get_all_widths();
fp->virtual_scr.VHeight =
fp->virtual_scr.VyPages * fpmonitor_get_all_heights();
fp->virtual_scr.VxMax =
fp->virtual_scr.VWidth - fpmonitor_get_all_widths();
fp->virtual_scr.VyMax =
fp->virtual_scr.VHeight - fpmonitor_get_all_heights();
ReConfigure();
}

if (do_reconfigure) {
Expand Down Expand Up @@ -428,10 +431,10 @@ void process_new_desk(unsigned long *body)
* and tracking is per-monitor or shared.
*/
if (!CurrentDeskPerMonitor && ((monitor_to_track != NULL &&
mout != monitor_to_track->m) ||
fp != monitor_to_track) ||
(current_monitor != NULL &&
monitor_to_track == NULL &&
mout != current_monitor->m &&
fp != current_monitor &&
(monitor_mode == MONITOR_TRACKING_M ||
is_tracking_shared))))
{
Expand All @@ -444,13 +447,6 @@ void process_new_desk(unsigned long *body)
/* Update the current desk. */
desk_i = newDesk;
style = FindDeskStyle(newDesk);
/* Create and update GCs if needed. */
if (oldDesk != newDesk) {
if (style->label_gc)
update_desk_style_gcs(style);
else
initialize_desk_style_gcs(style);
}

/* Keep monitors in sync when tracking is global. */
if (monitor_mode == MONITOR_TRACKING_G)
Expand All @@ -473,14 +469,14 @@ void process_new_desk(unsigned long *body)
update_desk_background(0);
update_monitor_locations(0);
update_monitor_backgrounds(0);
ReConfigureAll();
}

XStoreName(dpy, Scr.pager_w, style->label);
XSetIconName(dpy, Scr.pager_w, style->label);

update_grid:
MovePage();
ReConfigureAll();
draw_desk_grid(oldDesk - desk1);
draw_desk_grid(newDesk - desk1);
MoveStickyWindows(false, true);
Expand Down Expand Up @@ -932,7 +928,10 @@ void process_config_info_line(char *line, bool is_init)
{
PagerWindow *t = Start;

update_desk_style_gcs(style);
/* Only update if it wasn't updated previously. */
if (style->cs != color && style->hi_cs != color)
update_desk_style_gcs(style);

while (t != NULL) {
if (t->desk != style->desk) {
t = t->next;
Expand Down
4 changes: 4 additions & 0 deletions modules/FvwmPager/x_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ void update_desk_style_gcs(DeskStyle *style)
{
initialize_colorset(style);

/* Don't update GC's for default style. */
if (style->desk < 0)
return;

XSetForeground(dpy, style->label_gc, style->fg);
XSetForeground(dpy, style->dashed_gc, style->fg);
XSetForeground(dpy, style->hi_bg_gc, style->hi_bg);
Expand Down

0 comments on commit 0ca76da

Please sign in to comment.