Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added configuration options for issue #585 (kill menu, client name in title) #587

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions jwm.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1074,14 +1074,26 @@ that the value is relative to the bottom of the screen.
.B "WINDOW STYLE"
.RS
The \fBWindowStyle\fP tag controls the look of window borders.
This tag supports the following attribute:
This tag supports the following attributes:
.P
.B decorations
.RS
The window decorations to use. Valid options are \fBflat\fP and
\fBmotif\fP. \fBflat\fP is the default.
.RE
.P
.B machinename
Copy link
Owner

@joewing joewing Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of conflicted on the name. As is it sounds like you're setting the machine name. Even the code has showMachineName, but that's a little on the long side. Should it be named showmachine instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like showmachine better - will make the change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I think the attribute should be showclient since it is based on the WM_CLIENT_MACHINE property.

.RS
Include the X client machine name (WM_CLIENT_MACHINE) in the window title.
Valid options are \fBtrue\fP and \fBfalse\fP. \fBfalse\fP is the default.
.RE
.P
.B delimiters
.RS
The two characters used to wrap the X client machine name in the window title.
The default characters are \fB()\fP.
.RE
.P
Within this tag, the following tags are supported:
.P
.B Font
Expand Down Expand Up @@ -1257,7 +1269,7 @@ respectively.
.B "TASK LIST STYLE"
.RS
The \fBTaskListStyle\fP tag controls the look of task lists.
The following attributea are supported:
The following attributes are supported:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing all these typos!

.P
.B decorations
.RS
Expand All @@ -1279,6 +1291,13 @@ Possible values are \fBdesktop\fP and \fBall\fP. The default
is \fBdesktop\fP.
.RE
.P
.B killmenu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be showkill?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change this also...

.RS
Determines if the \fBKill\fP popup menu item is shown on task bars and
window title bars. Possible values are \fBtrue\fP and \fBfalse\fP. The default
is \fBtrue\fP.
.RE
.P
Within this tag the following tags are supported:
.P
.B Font
Expand Down
15 changes: 13 additions & 2 deletions src/border.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,17 @@ void DrawBorderHelper(const ClientNode *np)
if(np->name && np->name[0] && point.x < point.y) {
unsigned titleWidth = point.y - point.x;
const int sheight = GetStringHeight(FONT_BORDER);
const int textWidth = GetStringWidth(FONT_BORDER, np->name);
const int buffSize = (MAX_TITLE_LENGTH+1)*sizeof(char);
char *titleBuffer = calloc(MAX_TITLE_LENGTH+1,sizeof(char));
Copy link
Owner

@joewing joewing Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason behind a fixed length allocation? I suspect 512 is probably enough for most reasonable use-cases, but then the sprintfs should probably be switched to snprintfs. I think I'd be more comfortable just allocating the right amount though, which is maybe a little error prone, but I think this would work:

char *titleBuffer;
if(settings.showMachineName) {
   /* Space for 2 delimiters, space, terminator, and strings */
   const size_t bufSize = strlen(np->name) + strlen(np->machineName) + 4;
   titleBuffer = Allocate(bufSize);
   sprintf(titleBuffer, "%s %c%s%c", np->name,
           settings.machineNameDelimiters[0], np->machineName,
           settings.machineNameDelimiters[1]);
} else {
   titleBuffer = CopyString(np->name);
}
...
Release(titleBuffer);

Also, JWM has macros to wrap malloc/realloc/free (Allocate/Reallocate/Release), which I try to use to make it easy to check for memory leaks and buffer overruns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the suggested changes and remove the MAX_TITLE_LENGTH define

titleBuffer = memset(titleBuffer,'\0',buffSize);
if (settings.showMachineName){
sprintf(titleBuffer,"%s %c%s%c",np->name,
settings.machineNameDelimiters[0],np->machineName,
settings.machineNameDelimiters[1]);
} else {
sprintf(titleBuffer,"%s",np->name);
}
const int textWidth = GetStringWidth(FONT_BORDER,titleBuffer);
unsigned titlex, titley;
int xoffset = 0;

Expand All @@ -474,7 +484,8 @@ void DrawBorderHelper(const ClientNode *np)
titley += south - 1;
}
RenderString(canvas, FONT_BORDER, borderTextColor,
titlex, titley, titleWidth, np->name);
titlex, titley, titleWidth, titleBuffer);
free(titleBuffer);
}

}
Expand Down
22 changes: 22 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ static const char *DYNAMIC_ATTRIBUTE = "dynamic";
static const char *SPACING_ATTRIBUTE = "spacing";
static const char *TIMEOUT_ATTRIBUTE = "timeout";
static const char *POPUP_ATTRIBUTE = "popup";
static const char *MACHINENAME_ATTRIBUTE = "machinename";
static const char *MN_DELIMITERS_ATTRIBUTE = "delimiters";
static const char *KILL_MENU_ATTRIBUTE = "killmenu";

static const char *FALSE_VALUE = "false";
static const char *TRUE_VALUE = "true";
Expand Down Expand Up @@ -998,6 +1001,19 @@ void ParseWindowStyle(const TokenNode *tp)
{
const TokenNode *np;

const char *temp;
temp = FindAttribute(tp->attributes, MACHINENAME_ATTRIBUTE);
if(temp){
settings.showMachineName = !strcmp(temp,TRUE_VALUE);
}

temp = FindAttribute(tp->attributes, MN_DELIMITERS_ATTRIBUTE);
if(temp && strlen(temp)>=2) {
char *delims = calloc(strlen(temp)+1,sizeof(char));
sprintf(delims,"%s",temp);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would actually just declare settings.machineNameDelimiters as char machineNameDelimiters[2]; and just memcpy two characters here

settings.machineNameDelimiters = delims;
}

ParseDecorations(tp, &settings.windowDecorations);
for(np = tp->subnodeHead; np; np = np->next) {
switch(np->type) {
Expand Down Expand Up @@ -1203,6 +1219,12 @@ void ParseTrayStyle(const TokenNode *tp, FontType font, ColorType fg)
if(temp) {
settings.listAllTasks = !strcmp(temp, "all");
}

temp = FindAttribute(tp->attributes, KILL_MENU_ATTRIBUTE);
if(temp) {
settings.showKillMenuItem = !strcmp(temp, TRUE_VALUE);
}

} else if(tp->type == TOK_TRAYSTYLE) {
ParseDecorations(tp, &settings.trayDecorations);
}
Expand Down
3 changes: 3 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void InitializeSettings(void)
settings.groupTasks = 0;
settings.listAllTasks = 0;
settings.dockSpacing = 0;
settings.showMachineName = 0;
settings.machineNameDelimiters = DEFAULT_MACHINE_NAME_DELIMITERS;
settings.showKillMenuItem = 1;
memcpy(settings.titleBarLayout, DEFAULT_TITLE_BAR_LAYOUT,
sizeof(settings.titleBarLayout));
}
Expand Down
10 changes: 9 additions & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ typedef unsigned char DesktopBackAndForthType;
#define DBACKANDFORTH_OFF 0 /**< No back and forth */
#define DBACKANDFORTH_ON 1 /**< Enable back and forth */

/** Maximimum number of title bar components
/** Maximum number of title bar components
* For now, we allow each component to be used twice. */
#define TBC_COUNT 9

/** Maximum number of characters in window title
* and default characters for machine name delimiters. */
#define MAX_TITLE_LENGTH 512
#define DEFAULT_MACHINE_NAME_DELIMITERS "()"

/** Settings. */
typedef struct {
unsigned doubleClickSpeed;
Expand Down Expand Up @@ -122,6 +127,9 @@ typedef struct {
MouseContextType titleBarLayout[TBC_COUNT + 1];
char groupTasks;
char listAllTasks;
char showMachineName;
char *machineNameDelimiters;
char showKillMenuItem;
DesktopBackAndForthType desktopBackAndForth;
} Settings;

Expand Down
4 changes: 3 additions & 1 deletion src/winmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Menu *CreateWindowMenu(ClientNode *np)

if(!(np->state.status & STAT_WMDIALOG)) {
AddWindowMenuItem(menu, _("Close"), MA_CLOSE, np, 0);
AddWindowMenuItem(menu, _("Kill"), MA_KILL, np, 0);
if (settings.showKillMenuItem){
AddWindowMenuItem(menu, _("Kill"), MA_KILL, np, 0);
}
AddWindowMenuItem(menu, NULL, MA_NONE, np, 0);
}

Expand Down