Skip to content

Commit

Permalink
Fix error in FindScreenOfXY
Browse files Browse the repository at this point in the history
In the previous commit, I defined the m_min variable both inside
and outside of an if block (forgot to delete the inside one). So
delete the extra definition. Also set m_min to NULL to suppress
complier warnings. m_min should always be found, so exit if not.
  • Loading branch information
somiaj committed Oct 17, 2024
1 parent b2fe1e0 commit 530ee7c
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ monitor_get_count(void)
struct monitor *
FindScreenOfXY(int x, int y)
{
struct monitor *m;
struct monitor *m, *m_min = NULL;
int dmin = INT_MAX;
int all_widths = monitor_get_all_widths();
int all_heights = monitor_get_all_heights();

Expand All @@ -824,31 +825,35 @@ FindScreenOfXY(int x, int y)
return (m);
}

struct monitor *m_min;
if (m == NULL) {
/* No monitor found, point is in a dead area.
* Find closest monitor using the taxi cab metric.
*/
int dmin = INT_MAX;
struct monitor *m_min;

RB_FOREACH(m, monitors, &monitor_q) {
int d = 0;
if (x < m->si->x)
d += m->si->x - x;
if (x > m->si->x + m->si->w)
d += x - m->si->x - m->si->w;
if (y < m->si->y)
d += m->si->y - y;
if (y > m->si->y + m->si->h)
d += y - m->si->y - m->si->h;
if (d < dmin) {
dmin = d;
m_min = m;
}
/* No monitor found, point is in a dead area.
* Find closest monitor using the taxi cab metric.
*/
RB_FOREACH(m, monitors, &monitor_q) {
int d = 0;

/* Skip global screen */
if (strcmp(m->si->name, GLOBAL_SCREEN_NAME) == 0)
continue;

if (x < m->si->x)
d += m->si->x - x;
if (x > m->si->x + m->si->w)
d += x - m->si->x - m->si->w;
if (y < m->si->y)
d += m->si->y - y;
if (y > m->si->y + m->si->h)
d += y - m->si->y - m->si->h;
if (d < dmin) {
dmin = d;
m_min = m;
}
}

/* Shouldn't happen. */
if (m_min == NULL) {
fvwm_debug(__func__, "Couldn't find any monitor");
exit(106);
}
return (m_min);
}

Expand Down

0 comments on commit 530ee7c

Please sign in to comment.