Skip to content

Commit

Permalink
PanFrames: disallow Edge/Leave without direction
Browse files Browse the repository at this point in the history
Using EdgeCommand without a direction is now invalid - and hence to
clear a Edge/Leave command, the following has to be used:

    EdgeCommand Right
  • Loading branch information
ThomasAdam committed Dec 19, 2020
1 parent 355c34d commit e2eb087
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 92 deletions.
1 change: 1 addition & 0 deletions fvwm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,7 @@ ENTER_DBG((stderr, "en: exit: found LeaveNotify\n"));
}
else if (edge_command)
{
fvwm_debug(__func__, "EC is: %s", edge_command);
execute_function(NULL, ea->exc, edge_command, 0);
}
else
Expand Down
205 changes: 113 additions & 92 deletions fvwm/virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static int last_edge_thickness = 2;

static void store_desktop_cmd(int, char *);
static int number_of_desktops(struct monitor *);
static bool should_free_panframe(PanFrame *);

struct desktop_cmds desktop_cmd_q;
struct desktop_fws desktop_fvwm_q;
Expand Down Expand Up @@ -953,17 +954,26 @@ int HandlePaging(
* Hermann Dunkel, HEDU, dunkel@cul-ipn.uni-kiel.de 1/94
*/

static bool
should_free_panframe(PanFrame *pf)
{
if (pf->command != NULL || pf->command_leave != NULL)
return (false);

return (true);
}

/*
* checkPanFrames hides PanFrames if they are on the very border of the
* VIRTUAL screen and EdgeWrap for that direction is off.
* (A special cursor for the EdgeWrap border could be nice) HEDU
*/
void checkPanFrames(void)
{
Bool do_unmap_l = False;
Bool do_unmap_r = False;
Bool do_unmap_t = False;
Bool do_unmap_b = False;
Bool do_unmap_l = True;
Bool do_unmap_r = True;
Bool do_unmap_t = True;
Bool do_unmap_b = True;
struct monitor *m;

if (!Scr.flags.are_windows_captured)
Expand Down Expand Up @@ -1011,34 +1021,24 @@ void checkPanFrames(void)
}

/* correct the unmap variables if pan frame commands are set */
if (edge_thickness != 0)
{
if (m->PanFrameLeft.command != NULL ||
m->PanFrameLeft.command_leave != NULL)
{
do_unmap_l = False;
}
if (m->PanFrameRight.command != NULL ||
m->PanFrameRight.command_leave != NULL)
{
do_unmap_r = False;
}
if (m->PanFrameBottom.command != NULL ||
m->PanFrameBottom.command_leave != NULL)
{
do_unmap_b = False;
}
if (m->PanFrameTop.command != NULL ||
m->PanFrameTop.command_leave != NULL)
{
do_unmap_t = False;
}
}

if (!should_free_panframe(&m->PanFrameLeft))
do_unmap_l = False;
if (!should_free_panframe(&m->PanFrameRight))
do_unmap_r = False;
if (!should_free_panframe(&m->PanFrameBottom))
do_unmap_b = False;
if (!should_free_panframe(&m->PanFrameTop))
do_unmap_t = False;
/*
* hide or show the windows
*/

fvwm_debug(__func__,
"1 %s: {left: %d, right; %d, top: %d, bottom: %d}\n",
m->si->name,
m->PanFrameLeft.isMapped, m->PanFrameRight.isMapped,
m->PanFrameTop.isMapped, m->PanFrameBottom.isMapped);

/* left */
if (do_unmap_l)
{
Expand Down Expand Up @@ -1136,6 +1136,11 @@ void checkPanFrames(void)
}
}
last_edge_thickness = edge_thickness;
fvwm_debug(__func__,
"2 %s: {left: %d, right; %d, top: %d, bottom: %d}\n",
m->si->name,
m->PanFrameLeft.isMapped, m->PanFrameRight.isMapped,
m->PanFrameTop.isMapped, m->PanFrameBottom.isMapped);
}
}

Expand Down Expand Up @@ -1245,16 +1250,36 @@ void initPanFrames(void)
m->PanFrameRight.isMapped= m->PanFrameBottom.isMapped=False;
}
edge_thickness = saved_thickness;
checkPanFrames();
}

Bool is_pan_frame(Window w)
{
struct monitor *m;

TAILQ_FOREACH(m, &monitor_q, entry) {
if (w == m->PanFrameTop.win || w == m->PanFrameBottom.win ||
w == m->PanFrameLeft.win || w == m->PanFrameRight.win)
{
bool is_pf_top = (w == m->PanFrameTop.win);
bool is_pf_bottom = (w == m->PanFrameBottom.win);
bool is_pf_left = (w == m->PanFrameLeft.win);
bool is_pf_right = (w == m->PanFrameRight.win);

if (is_pf_top) {
fvwm_debug(__func__, "Window is PanFrame top\n");
return True;
}

if (is_pf_bottom) {
fvwm_debug(__func__, "Window is PanFrame bottom\n");
return True;
}

if (is_pf_left) {
fvwm_debug(__func__, "Window is PanFrame left\n");
return True;
}

if (is_pf_right) {
fvwm_debug(__func__, "Window is PanFrame right\n");
return True;
}
}
Expand Down Expand Up @@ -1825,46 +1850,60 @@ char *GetDesktopName(struct monitor *m, int desk)
void CMD_EdgeCommand(F_CMD_ARGS)
{
direction_t direction;
char *command;
char *command = NULL, *actdup, *rest;
struct monitor *m;

if (action != NULL)
actdup = fxstrdup(action);

/* get the direction */
direction = gravity_parse_dir_argument(action, &action, DIR_NONE);

if (direction >= 0 && direction <= DIR_MAJOR_MASK)
{

/* check if the command does contain at least one token */
command = fxstrdup(action);
if (PeekToken(action , &action) == NULL)
rest = GetNextToken(actdup , &action);
if (rest == NULL || *rest == '\0')
{
/* the command does not contain a token so
the command of this edge is removed */
free(command);
command = fxstrdup("");
}
command = NULL;
} else
command = fxstrdup(rest);

TAILQ_FOREACH(m, &monitor_q, entry) {
/* assign command to the edge(s) */
if (direction == DIR_N)
{
free(m->PanFrameTop.command);
m->PanFrameTop.command = fxstrdup(command);
m->PanFrameTop.command = NULL;
if (command != NULL)
m->PanFrameTop.command = fxstrdup(command);
}
else if (direction == DIR_S)
{
free(m->PanFrameBottom.command);
m->PanFrameBottom.command = fxstrdup(command);
m->PanFrameBottom.command = NULL;
if (command != NULL)
m->PanFrameBottom.command = fxstrdup(command);
}
else if (direction == DIR_W)
{
free(m->PanFrameLeft.command);
m->PanFrameLeft.command = fxstrdup(command);
m->PanFrameLeft.command = NULL;
if (command != NULL)
m->PanFrameLeft.command = fxstrdup(command);
}
else if (direction == DIR_E)
{
free(m->PanFrameRight.command);
m->PanFrameRight.command = fxstrdup(command);
m->PanFrameRight.command = NULL;
if (command != NULL)
m->PanFrameRight.command = fxstrdup(command);

fvwm_debug(__func__, "RIGHT IS: %s",
m->PanFrameRight.command);
}
else
{
Expand All @@ -1873,29 +1912,13 @@ void CMD_EdgeCommand(F_CMD_ARGS)
"Internal error in CMD_EdgeCommand");
}
}
free(command);
free(actdup);
} else {
fvwm_debug(__func__, "EdgeCommand needs a direction\n");
free(actdup);
return;
}
else
{

/* check if the argument does contain at least one token */
if (PeekToken(action , &action) == NULL)
{
/* Just plain EdgeCommand, so all edge commands are
* removed */

TAILQ_FOREACH(m, &monitor_q, entry) {
free(m->PanFrameTop.command);
free(m->PanFrameBottom.command);
free(m->PanFrameLeft.command);
free(m->PanFrameRight.command);
}
} else {
/* not a proper direction */
fvwm_debug(__func__,
"EdgeCommand [direction [function]]");
}
}

/* maybe something has changed so we adapt the pan frames */
checkPanFrames();
}
Expand All @@ -1904,72 +1927,70 @@ void CMD_EdgeCommand(F_CMD_ARGS)
void CMD_EdgeLeaveCommand(F_CMD_ARGS)
{
direction_t direction;
char *command;
char *command = NULL, *actdup, *rest;
struct monitor *m;

if (action != NULL)
actdup = fxstrdup(action);

/* get the direction */
direction = gravity_parse_dir_argument(action, &action, DIR_NONE);

if (direction >= 0 && direction <= DIR_MAJOR_MASK)
{

/* check if the command does contain at least one token */
command = fxstrdup(action);
if (PeekToken(action , &action) == NULL)
rest = GetNextToken(actdup , &action);
if (rest == NULL || *rest == '\0')
{
/* the command does not contain a token so
the command of this edge is removed */
free(command);
command = fxstrdup("");
}
command = NULL;
} else
command = fxstrdup(rest);

TAILQ_FOREACH(m, &monitor_q, entry) {
/* assign command to the edge(s) */
if (direction == DIR_N)
{
free(m->PanFrameTop.command_leave);
m->PanFrameTop.command_leave = fxstrdup(command);
m->PanFrameTop.command_leave = NULL;
if (command != NULL)
m->PanFrameTop.command_leave = fxstrdup(command);
}
else if (direction == DIR_S)
{
free(m->PanFrameBottom.command_leave);
m->PanFrameBottom.command_leave = fxstrdup(command);
m->PanFrameBottom.command_leave = NULL;
if (command != NULL)
m->PanFrameBottom.command_leave = fxstrdup(command);
}
else if (direction == DIR_W)
{
free(m->PanFrameLeft.command_leave);
m->PanFrameLeft.command_leave = fxstrdup(command);
m->PanFrameLeft.command_leave = NULL;
if (command != NULL)
m->PanFrameLeft.command_leave = fxstrdup(command);
}
else if (direction == DIR_E)
{
free(m->PanFrameRight.command_leave);
m->PanFrameRight.command_leave = fxstrdup(command);
m->PanFrameRight.command_leave = NULL;
if (command != NULL)
m->PanFrameRight.command_leave = fxstrdup(command);
}
else
{
/* this should never happen */
fvwm_debug(__func__, "Internal error");
}
}
}
else
{
/* check if the argument does contain at least one token */
if (PeekToken(action , &action) == NULL)
{
/* Just plain EdgeLeaveCommand, so all edge commands are
* removed */
TAILQ_FOREACH(m, &monitor_q, entry) {
free(m->PanFrameTop.command_leave);
free(m->PanFrameBottom.command_leave);
free(m->PanFrameLeft.command_leave);
free(m->PanFrameRight.command_leave);
}
} else {
/* not a proper direction */
fvwm_debug(__func__,
"EdgeLeaveCommand [direction [function]]");
}
free(command);
free(actdup);
} else {
fvwm_debug(__func__, "EdgeLeaveCommand needs a direction");
free(actdup);
return;
}

/* maybe something has changed so we adapt the pan frames */
Expand Down

0 comments on commit e2eb087

Please sign in to comment.