Skip to content

Commit

Permalink
FvwmPager: Restructure initialization methods.
Browse files Browse the repository at this point in the history
* Split up the large initialization method into smaller methods to better
  group related pieces of the initialization together.
* Cleaup variable use, don't store font names, just create the font and
  discard the name, reducing pointer usage.
* Cleanup ExitPager() to try to catch any remaining pointers to free.
* Group the -transient pager initialization together and update it to
  place the pager under the pointer. In addition update the position
  using fpmonitors to ensure the pager isn't off screen.
  • Loading branch information
somiaj committed Apr 20, 2024
1 parent 6601199 commit b8aa7cf
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 514 deletions.
88 changes: 47 additions & 41 deletions modules/FvwmPager/FvwmPager.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "libs/Grab.h"
#include "libs/Parse.h"
#include "libs/Strings.h"
#include "libs/Picture.h"
#include "libs/System.h"

#include "fvwm/fvwm.h"
Expand All @@ -48,22 +49,21 @@
* Shared variables.
*/
/* Colors, Pixmaps, Fonts, etc. */
char *smallFont = NULL;
char *ImagePath = NULL;
char *font_string = NULL;
char *BalloonFont = NULL;
char *WindowLabelFormat = NULL;
Pixmap default_pixmap = None;
FlocaleFont *Ffont;
FlocaleFont *FwindowFont;
FlocaleWinString *FwinString;
Atom wm_del_win;

/* Sizes / Dimensions */
int Rows = -1;
int desk1 = 0;
int desk2 = 0;
int desk_i = 0;
int ndesks = 0;
int desk_w = 0;
int desk_h = 0;
int label_h = 0;
int Columns = -1;
int MoveThreshold = DEFAULT_PAGER_MOVE_THRESHOLD;
int BalloonBorderWidth = DEFAULT_BALLOON_BORDER_WIDTH;
Expand All @@ -75,14 +75,9 @@ rectangle pwindow = {0, 0, 0, 0};
rectangle icon = {-10000, -10000, 0, 0};

/* Settings */
bool xneg = false;
bool yneg = false;
bool IsShared = false;
bool icon_xneg = false;
bool icon_yneg = false;
bool MiniIcons = false;
bool Swallowed = false;
bool usposition = false;
bool UseSkipList = false;
bool StartIconic = false;
bool LabelsBelow = false;
Expand Down Expand Up @@ -420,30 +415,37 @@ DeskStyle *FindDeskStyle(int desk)

void ExitPager(void)
{
DeskStyle *style, *style2;
struct fpmonitor *fp, *fp1;
PagerWindow *t, *t2;

/* Balloons */
free(Balloon.label);
free(Balloon.label_format);

/* Monitors */
TAILQ_FOREACH_SAFE(fp, &fp_monitor_q, entry, fp1) {
TAILQ_REMOVE(&fp_monitor_q, fp, entry);
free(fp->CPagerWin);
free(fp);
}
DeskStyle *style, *style2;
struct fpmonitor *fp, *fp1;
PagerWindow *t, *t2;

/* Balloons */
free(Balloon.label);
free(Balloon.label_format);

/* Fonts */
FlocaleUnloadFont(dpy, Scr.Ffont);
FlocaleUnloadFont(dpy, Scr.winFfont);
FlocaleUnloadFont(dpy, Balloon.Ffont);

/* Monitors */
TAILQ_FOREACH_SAFE(fp, &fp_monitor_q, entry, fp1) {
TAILQ_REMOVE(&fp_monitor_q, fp, entry);
free(fp->CPagerWin);
free(fp);
}

/* DeskStyles */
TAILQ_FOREACH_SAFE(style, &desk_style_q, entry, style2) {
TAILQ_REMOVE(&desk_style_q, style, entry);
free(style->label);
free(style);
}
free(Desks);
/* DeskStyles */
TAILQ_FOREACH_SAFE(style, &desk_style_q, entry, style2) {
TAILQ_REMOVE(&desk_style_q, style, entry);
PDestroyFvwmPicture(dpy, style->bgPixmap);
PDestroyFvwmPicture(dpy, style->hiPixmap);
free(style->label);
free(style);
}
free(Desks);

/* PagerWindows */
/* PagerWindows */
t2 = Start;
while (t2 != NULL) {
t = t2;
Expand All @@ -459,13 +461,17 @@ void ExitPager(void)
free(t);
}

if (is_transient)
{
XUngrabPointer(dpy,CurrentTime);
MyXUngrabServer(dpy);
XSync(dpy,0);
}
XUngrabKeyboard(dpy, CurrentTime);
free(preferred_monitor);
exit(0);
/* Additional pointers */
free(preferred_monitor);
free(ImagePath);
free(WindowLabelFormat);

if (is_transient) {
XUngrabPointer(dpy, CurrentTime);
MyXUngrabServer(dpy);
XSync(dpy, 0);
}
XUngrabKeyboard(dpy, CurrentTime);

exit(0);
}
26 changes: 6 additions & 20 deletions modules/FvwmPager/FvwmPager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ typedef struct ScreenInfo
Window label_w;
Window balloon_w;

Font PagerFont; /* font struct for window labels in pager (optional)*/
FlocaleFont *Ffont;
FlocaleFont *winFfont;

GC NormalGC; /* used for window names and setting backgrounds */
GC MiniIconGC; /* used for clipping mini-icons */

unsigned VScale; /* Panner scale factor */

Pixmap sticky_gray_pixmap;
Pixmap light_gray_pixmap;
Pixmap gray_pixmap;
Expand Down Expand Up @@ -169,17 +171,9 @@ typedef struct desk_info
/*
* Shared variables.
*/
/* Colors, Pixmaps, Fonts, etc. */
extern char *smallFont;
/* Misc */
extern char *ImagePath;
extern char *font_string;
extern char *BalloonFont;
extern char *WindowLabelFormat;
extern Pixel focus_win_fg;
extern Pixel focus_win_bg;
extern Pixmap default_pixmap;
extern FlocaleFont *Ffont;
extern FlocaleFont *FwindowFont;
extern FlocaleWinString *FwinString;
extern Atom wm_del_win;

Expand All @@ -200,14 +194,9 @@ extern rectangle pwindow;
extern rectangle icon;

/* Settings */
extern bool xneg;
extern bool yneg;
extern bool IsShared;
extern bool icon_xneg;
extern bool icon_yneg;
extern bool MiniIcons;
extern bool Swallowed;
extern bool usposition;
extern bool UseSkipList;
extern bool StartIconic;
extern bool LabelsBelow;
Expand Down Expand Up @@ -258,6 +247,7 @@ void DispatchEvent(XEvent *Event);
void ReConfigure(void);
void ReConfigureAll(void);
void MovePage();
void set_desk_size(bool update_label);
void draw_desk_grid(int desk);
void AddNewWindow(PagerWindow *prev);
void ChangeDeskForWindow(PagerWindow *t,long newdesk);
Expand Down Expand Up @@ -292,11 +282,7 @@ int fpmonitor_count(void);

/* messages.c methods */
void process_message(FvwmPacket *packet);
void set_desk_label(int desk, const char *label);
void set_desk_size(bool update_label);
void parse_monitor_line(char *tline);
void parse_desktop_size_line(char *tline);
void parse_desktop_configuration_line(char *tline);
void process_config_info_line(char *line, bool is_init);
void update_monitor_to_track(struct fpmonitor **fp_track,
char *name, bool update_prefered);

Expand Down
Loading

0 comments on commit b8aa7cf

Please sign in to comment.