* Make some functions in win.c pure
* Remove unused code
* Fix misuse of attr_const, const functions shouldn't exam data pointed
  to by its pointer arguments.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-21 14:08:08 +00:00
parent 69826a0844
commit 350933a054
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
7 changed files with 71 additions and 82 deletions

View File

@ -514,7 +514,7 @@ paint_preprocess(session_t *ps, bool *fade_running) {
} }
// Update window mode // Update window mode
win_determine_mode(ps, w); w->mode = win_calc_mode(w);
// Destroy all reg_ignore above when frame opaque state changes on // Destroy all reg_ignore above when frame opaque state changes on
// SOLID mode // SOLID mode
@ -897,7 +897,7 @@ configure_win(session_t *ps, xcb_configure_notify_event_t *ce) {
w->g.width = ce->width; w->g.width = ce->width;
w->g.height = ce->height; w->g.height = ce->height;
w->g.border_width = ce->border_width; w->g.border_width = ce->border_width;
calc_win_size(ps, w); win_on_win_size_change(ps, w);
win_update_bounding_shape(ps, w); win_update_bounding_shape(ps, w);
} }
@ -1405,7 +1405,7 @@ ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
if (ev->atom == ps->atom_win_type) { if (ev->atom == ps->atom_win_type) {
win *w = NULL; win *w = NULL;
if ((w = find_toplevel(ps, ev->window))) if ((w = find_toplevel(ps, ev->window)))
win_upd_wintype(ps, w); win_update_wintype(ps, w);
} }
// If _NET_WM_OPACITY changes // If _NET_WM_OPACITY changes
@ -1419,7 +1419,7 @@ ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
// See the winstate_t transition table // See the winstate_t transition table
w->state = WSTATE_FADING; w->state = WSTATE_FADING;
} }
w->opacity_tgt = win_get_opacity_target(ps, w); w->opacity_tgt = win_calc_opacity_target(ps, w);
} }
} }

View File

@ -41,16 +41,6 @@ find_client_win(session_t *ps, xcb_window_t w);
win *find_toplevel2(session_t *ps, xcb_window_t wid); win *find_toplevel2(session_t *ps, xcb_window_t wid);
/**
* Subtract two unsigned long values.
*
* Truncate to 0 if the result is negative.
*/
static inline unsigned long attr_const
sub_unslong(unsigned long a, unsigned long b) {
return (a > b) ? a - b : 0;
}
/** /**
* Set a <code>switch_t</code> array of all unset wintypes to true. * Set a <code>switch_t</code> array of all unset wintypes to true.
*/ */

View File

@ -284,7 +284,7 @@ char *parse_config(options_t *, const char *config_file, bool *shadow_enable,
/** /**
* Parse a backend option argument. * Parse a backend option argument.
*/ */
static inline attr_const enum backend parse_backend(const char *str) { static inline attr_pure enum backend parse_backend(const char *str) {
for (enum backend i = 0; BACKEND_STRS[i]; ++i) { for (enum backend i = 0; BACKEND_STRS[i]; ++i) {
if (!strcasecmp(str, BACKEND_STRS[i])) { if (!strcasecmp(str, BACKEND_STRS[i])) {
return i; return i;
@ -311,7 +311,7 @@ static inline attr_const enum backend parse_backend(const char *str) {
* *
* Returns -2 on failure * Returns -2 on failure
*/ */
static inline attr_const int parse_glx_swap_method(const char *str) { static inline attr_pure int parse_glx_swap_method(const char *str) {
// Parse alias // Parse alias
if (!strcmp("undefined", str)) { if (!strcmp("undefined", str)) {
return 0; return 0;

View File

@ -15,8 +15,8 @@ typedef struct conv {
/// Calculate the sum of a rectangle part of the convolution kernel /// Calculate the sum of a rectangle part of the convolution kernel
/// the rectangle is defined by top left (x, y), and a size (width x height) /// the rectangle is defined by top left (x, y), and a size (width x height)
double attr_const sum_kernel(const conv *map, int x, int y, int width, int height); double attr_pure sum_kernel(const conv *map, int x, int y, int width, int height);
double attr_const sum_kernel_normalized(const conv *map, int x, int y, int width, int height); double attr_pure sum_kernel_normalized(const conv *map, int x, int y, int width, int height);
/// Create a kernel with gaussian distribution of radius r /// Create a kernel with gaussian distribution of radius r
conv *gaussian_kernel(double r); conv *gaussian_kernel(double r);

View File

@ -49,7 +49,7 @@ attr_nonnull_all void log_destroy(struct log *);
attr_nonnull(1) void log_set_level(struct log *l, int level); attr_nonnull(1) void log_set_level(struct log *l, int level);
attr_pure enum log_level log_get_level(const struct log *l); attr_pure enum log_level log_get_level(const struct log *l);
attr_nonnull_all void log_add_target(struct log *, struct log_target *); attr_nonnull_all void log_add_target(struct log *, struct log_target *);
attr_const enum log_level string_to_log_level(const char *); attr_pure enum log_level string_to_log_level(const char *);
/// Remove a previously added log target for a log struct, and destroy it. If the log /// Remove a previously added log target for a log struct, and destroy it. If the log
/// target was never added, nothing happens. /// target was never added, nothing happens.
void log_remove_target(struct log *l, struct log_target *tgt); void log_remove_target(struct log *l, struct log_target *tgt);

View File

@ -43,7 +43,7 @@
/// Generate a "return by value" function, from a function that returns the /// Generate a "return by value" function, from a function that returns the
/// region via a region_t pointer argument. /// region via a region_t pointer argument.
/// Function signature has to be (win *, region_t *) /// Function signature has to be (win *, region_t *)
#define gen_by_val(fun) region_t fun##_by_val(win *w) { \ #define gen_by_val(fun) region_t fun##_by_val(const win *w) { \
region_t ret; \ region_t ret; \
pixman_region32_init(&ret); \ pixman_region32_init(&ret); \
fun(w, &ret); \ fun(w, &ret); \
@ -112,7 +112,7 @@ group_is_focused(session_t *ps, xcb_window_t leader) {
/** /**
* Get a rectangular region a window occupies, excluding shadow. * Get a rectangular region a window occupies, excluding shadow.
*/ */
static void win_get_region_local(session_t *ps, win *w, region_t *res) { static void win_get_region_local(const win *w, region_t *res) {
pixman_region32_fini(res); pixman_region32_fini(res);
pixman_region32_init_rect(res, 0, 0, w->widthb, w->heightb); pixman_region32_init_rect(res, 0, 0, w->widthb, w->heightb);
} }
@ -121,7 +121,7 @@ static void win_get_region_local(session_t *ps, win *w, region_t *res) {
/** /**
* Get a rectangular region a window occupies, excluding frame and shadow. * Get a rectangular region a window occupies, excluding frame and shadow.
*/ */
void win_get_region_noframe_local(win *w, region_t *res) { void win_get_region_noframe_local(const win *w, region_t *res) {
const margin_t extents = win_calc_frame_extents(w); const margin_t extents = win_calc_frame_extents(w);
int x = extents.left; int x = extents.left;
@ -156,15 +156,15 @@ void add_damage_from_win(session_t *ps, win *w) {
* Check if a window has rounded corners. * Check if a window has rounded corners.
* XXX This is really dumb * XXX This is really dumb
*/ */
void win_rounded_corners(session_t *ps, win *w) { static bool attr_pure win_has_rounded_corners(const win *w) {
w->rounded_corners = false; if (!w->bounding_shaped) {
return false;
if (!w->bounding_shaped) }
return;
// Quit if border_size() returns XCB_NONE // Quit if border_size() returns XCB_NONE
if (!pixman_region32_not_empty(&w->bounding_shape)) if (!pixman_region32_not_empty((region_t *)&w->bounding_shape)) {
return; return false;
}
// Determine the minimum width/height of a rectangle that could mark // Determine the minimum width/height of a rectangle that could mark
// a window as having rounded corners // a window as having rounded corners
@ -175,15 +175,16 @@ void win_rounded_corners(session_t *ps, win *w) {
// Get the rectangles in the bounding region // Get the rectangles in the bounding region
int nrects = 0; int nrects = 0;
const rect_t *rects = pixman_region32_rectangles(&w->bounding_shape, &nrects); const rect_t *rects = pixman_region32_rectangles((region_t *)&w->bounding_shape, &nrects);
// Look for a rectangle large enough for this window be considered // Look for a rectangle large enough for this window be considered
// having rounded corners // having rounded corners
for (int i = 0; i < nrects; ++i) for (int i = 0; i < nrects; ++i) {
if (rects[i].x2 - rects[i].x1 >= minwidth && rects[i].y2 - rects[i].y1 >= minheight) { if (rects[i].x2 - rects[i].x1 >= minwidth && rects[i].y2 - rects[i].y1 >= minheight) {
w->rounded_corners = true; return true;
break;
} }
}
return false;
} }
int win_get_name(session_t *ps, win *w) { int win_get_name(session_t *ps, win *w) {
@ -265,7 +266,8 @@ static inline bool win_bounding_shaped(const session_t *ps, xcb_window_t wid) {
return false; return false;
} }
wintype_t wid_get_prop_wintype(session_t *ps, xcb_window_t wid) { static wintype_t
wid_get_prop_wintype(session_t *ps, xcb_window_t wid) {
winprop_t prop = wid_get_prop(ps, wid, ps->atom_win_type, 32L, XCB_ATOM_ATOM, 32); winprop_t prop = wid_get_prop(ps, wid, ps->atom_win_type, 32L, XCB_ATOM_ATOM, 32);
for (unsigned i = 0; i < prop.nitems; ++i) { for (unsigned i = 0; i < prop.nitems; ++i) {
@ -282,8 +284,9 @@ wintype_t wid_get_prop_wintype(session_t *ps, xcb_window_t wid) {
return WINTYPE_UNKNOWN; return WINTYPE_UNKNOWN;
} }
bool wid_get_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t def, static bool
opacity_t *out) { wid_get_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t def,
opacity_t *out) {
bool ret = false; bool ret = false;
*out = def; *out = def;
@ -306,14 +309,14 @@ bool win_has_alpha(const win *w) {
w->pictfmt->direct.alpha_mask; w->pictfmt->direct.alpha_mask;
} }
void win_determine_mode(session_t *ps, win *w) { winmode_t win_calc_mode(const win *w) {
if (win_has_alpha(w) || w->opacity < 1.0) { if (win_has_alpha(w) || w->opacity < 1.0) {
w->mode = WMODE_TRANS; return WMODE_TRANS;
} else if (w->frame_opacity != 1.0) {
w->mode = WMODE_FRAME_TRANS;
} else {
w->mode = WMODE_SOLID;
} }
if (w->frame_opacity != 1.0) {
return WMODE_FRAME_TRANS;
}
return WMODE_SOLID;
} }
/** /**
@ -336,7 +339,7 @@ void win_determine_mode(session_t *ps, win *w) {
* *
* @return target opacity * @return target opacity
*/ */
double win_get_opacity_target(session_t *ps, const win *w) { double win_calc_opacity_target(session_t *ps, const win *w) {
double opacity = 1; double opacity = 1;
if (w->state == WSTATE_UNMAPPED) { if (w->state == WSTATE_UNMAPPED) {
@ -604,10 +607,13 @@ void win_on_factor_change(session_t *ps, win *w) {
/** /**
* Update cache data in struct _win that depends on window size. * Update cache data in struct _win that depends on window size.
*/ */
void calc_win_size(session_t *ps, win *w) { void win_on_win_size_change(session_t *ps, win *w) {
w->widthb = w->g.width + w->g.border_width * 2; w->widthb = w->g.width + w->g.border_width * 2;
w->heightb = w->g.height + w->g.border_width * 2; w->heightb = w->g.height + w->g.border_width * 2;
calc_shadow_geometry(ps, w); w->shadow_dx = ps->o.shadow_offset_x;
w->shadow_dy = ps->o.shadow_offset_y;
w->shadow_width = w->widthb + ps->o.shadow_radius * 2;
w->shadow_height = w->heightb + ps->o.shadow_radius * 2;
w->flags |= WFLAG_SIZE_CHANGE; w->flags |= WFLAG_SIZE_CHANGE;
// Invalidate the shadow we built // Invalidate the shadow we built
if (ps->o.experimental_backends) { if (ps->o.experimental_backends) {
@ -628,20 +634,10 @@ void calc_win_size(session_t *ps, win *w) {
} }
} }
/**
* Calculate and update geometry of the shadow of a window.
*/
void calc_shadow_geometry(session_t *ps, win *w) {
w->shadow_dx = ps->o.shadow_offset_x;
w->shadow_dy = ps->o.shadow_offset_y;
w->shadow_width = w->widthb + ps->o.shadow_radius * 2;
w->shadow_height = w->heightb + ps->o.shadow_radius * 2;
}
/** /**
* Update window type. * Update window type.
*/ */
void win_upd_wintype(session_t *ps, win *w) { void win_update_wintype(session_t *ps, win *w) {
const wintype_t wtype_old = w->window_type; const wintype_t wtype_old = w->window_type;
// Detect window type here // Detect window type here
@ -686,7 +682,7 @@ void win_mark_client(session_t *ps, win *w, xcb_window_t client) {
free(e); free(e);
} }
win_upd_wintype(ps, w); win_update_wintype(ps, w);
// Get frame widths. The window is in damaged area already. // Get frame widths. The window is in damaged area already.
if (ps->o.frame_opacity != 1) if (ps->o.frame_opacity != 1)
@ -924,7 +920,7 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
new->pictfmt = x_get_pictform_for_visual(ps->c, new->a.visual); new->pictfmt = x_get_pictform_for_visual(ps->c, new->a.visual);
} }
calc_win_size(ps, new); win_on_win_size_change(ps, new);
// Find window insertion point // Find window insertion point
win **p = NULL; win **p = NULL;
@ -978,7 +974,7 @@ void win_update_focused(session_t *ps, win *w) {
// Always recalculate the window target opacity, since some opacity-related // Always recalculate the window target opacity, since some opacity-related
// options depend on the output value of win_is_focused_real() instead of // options depend on the output value of win_is_focused_real() instead of
// w->focused // w->focused
w->opacity_tgt = win_get_opacity_target(ps, w); w->opacity_tgt = win_calc_opacity_target(ps, w);
w->state = WSTATE_FADING; w->state = WSTATE_FADING;
} }
@ -1176,7 +1172,7 @@ win_set_focused(session_t *ps, win *w, bool focused) {
* Note w->shadow and shadow geometry must be correct before calling this * Note w->shadow and shadow geometry must be correct before calling this
* function. * function.
*/ */
void win_extents(win *w, region_t *res) { void win_extents(const win *w, region_t *res) {
pixman_region32_clear(res); pixman_region32_clear(res);
pixman_region32_union_rect(res, res, w->g.x, w->g.y, w->widthb, w->heightb); pixman_region32_union_rect(res, res, w->g.x, w->g.y, w->widthb, w->heightb);
@ -1198,7 +1194,7 @@ void win_update_bounding_shape(session_t *ps, win *w) {
pixman_region32_clear(&w->bounding_shape); pixman_region32_clear(&w->bounding_shape);
// Start with the window rectangular region // Start with the window rectangular region
win_get_region_local(ps, w, &w->bounding_shape); win_get_region_local(w, &w->bounding_shape);
// Only request for a bounding region if the window is shaped // Only request for a bounding region if the window is shaped
// (while loop is used to avoid goto, not an actual loop) // (while loop is used to avoid goto, not an actual loop)
@ -1236,8 +1232,9 @@ void win_update_bounding_shape(session_t *ps, win *w) {
break; break;
} }
if (w->bounding_shaped && ps->o.detect_rounded_corners) if (w->bounding_shaped && ps->o.detect_rounded_corners) {
win_rounded_corners(ps, w); w->rounded_corners = win_has_rounded_corners(w);
}
// Window shape changed, we should free old wpaint and shadow pict // Window shape changed, we should free old wpaint and shadow pict
if (ps->o.experimental_backends) { if (ps->o.experimental_backends) {
@ -1312,7 +1309,7 @@ win_update_frame_extents(session_t *ps, win *w, xcb_window_t client) {
free_winprop(&prop); free_winprop(&prop);
} }
bool win_is_region_ignore_valid(session_t *ps, win *w) { bool win_is_region_ignore_valid(session_t *ps, const win *w) {
for(win *i = ps->list; w; w = w->next) { for(win *i = ps->list; w; w = w->next) {
if (i == w) if (i == w)
break; break;
@ -1325,7 +1322,7 @@ bool win_is_region_ignore_valid(session_t *ps, win *w) {
/** /**
* Stop listening for events on a particular window. * Stop listening for events on a particular window.
*/ */
void win_ev_stop(session_t *ps, win *w) { void win_ev_stop(session_t *ps, const win *w) {
xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 }); xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 });
if (w->client_win) { if (w->client_win) {
@ -1466,7 +1463,7 @@ unmap_win(session_t *ps, win **_w, bool destroy) {
w->a.map_state = XCB_MAP_STATE_UNMAPPED; w->a.map_state = XCB_MAP_STATE_UNMAPPED;
w->state = target_state; w->state = target_state;
w->opacity_tgt = win_get_opacity_target(ps, w); w->opacity_tgt = win_calc_opacity_target(ps, w);
w->in_openclose = destroy; w->in_openclose = destroy;
@ -1591,7 +1588,7 @@ void map_win(session_t *ps, win *w) {
} }
// Update window mode here to check for ARGB windows // Update window mode here to check for ARGB windows
win_determine_mode(ps, w); w->mode = win_calc_mode(w);
// Detect client window here instead of in add_win() as the client // Detect client window here instead of in add_win() as the client
// window should have been prepared at this point // window should have been prepared at this point
@ -1622,7 +1619,7 @@ void map_win(session_t *ps, win *w) {
// XXX We need to make sure that win_data is available // XXX We need to make sure that win_data is available
// iff `state` is MAPPED // iff `state` is MAPPED
w->state = WSTATE_MAPPING; w->state = WSTATE_MAPPING;
w->opacity_tgt = win_get_opacity_target(ps, w); w->opacity_tgt = win_calc_opacity_target(ps, w);
log_debug("Window %#010x has opacity %f, opacity target is %f", w->id, w->opacity, w->opacity_tgt); log_debug("Window %#010x has opacity %f, opacity target is %f", w->id, w->opacity, w->opacity_tgt);
win_determine_blur_background(ps, w); win_determine_blur_background(ps, w);

View File

@ -282,12 +282,12 @@ struct win {
int win_get_name(session_t *ps, win *w); int win_get_name(session_t *ps, win *w);
int win_get_role(session_t *ps, win *w); int win_get_role(session_t *ps, win *w);
void win_determine_mode(session_t *ps, win *w); winmode_t attr_pure win_calc_mode(const win *w);
/** /**
* Set real focused state of a window. * Set real focused state of a window.
*/ */
void win_set_focused(session_t *ps, win *w, bool focused); void win_set_focused(session_t *ps, win *w, bool focused);
bool attr_const win_should_fade(session_t *ps, const win *w); bool attr_pure win_should_fade(session_t *ps, const win *w);
void win_update_prop_shadow_raw(session_t *ps, win *w); void win_update_prop_shadow_raw(session_t *ps, win *w);
void win_update_prop_shadow(session_t *ps, win *w); void win_update_prop_shadow(session_t *ps, win *w);
void win_set_shadow(session_t *ps, win *w, bool shadow_new); void win_set_shadow(session_t *ps, win *w, bool shadow_new);
@ -298,16 +298,18 @@ void win_set_blur_background(session_t *ps, win *w, bool blur_background_new);
void win_determine_blur_background(session_t *ps, win *w); void win_determine_blur_background(session_t *ps, win *w);
void win_on_wtype_change(session_t *ps, win *w); void win_on_wtype_change(session_t *ps, win *w);
void win_on_factor_change(session_t *ps, win *w); void win_on_factor_change(session_t *ps, win *w);
void calc_win_size(session_t *ps, win *w); /**
void calc_shadow_geometry(session_t *ps, win *w); * Update cache data in struct _win that depends on window size.
void win_upd_wintype(session_t *ps, win *w); */
void win_on_win_size_change(session_t *ps, win *w);
void win_update_wintype(session_t *ps, win *w);
void win_mark_client(session_t *ps, win *w, xcb_window_t client); void win_mark_client(session_t *ps, win *w, xcb_window_t client);
void win_unmark_client(session_t *ps, win *w); void win_unmark_client(session_t *ps, win *w);
void win_recheck_client(session_t *ps, win *w); void win_recheck_client(session_t *ps, win *w);
xcb_window_t win_get_leader_raw(session_t *ps, win *w, int recursions); xcb_window_t win_get_leader_raw(session_t *ps, win *w, int recursions);
bool win_get_class(session_t *ps, win *w); bool win_get_class(session_t *ps, win *w);
double attr_const win_get_opacity_target(session_t *ps, const win *w); double attr_pure win_calc_opacity_target(session_t *ps, const win *w);
bool attr_const win_should_dim(session_t *ps, const win *w); bool attr_pure win_should_dim(session_t *ps, const win *w);
void win_update_screen(session_t *, win *); void win_update_screen(session_t *, win *);
/// Prepare window for fading because opacity target changed /// Prepare window for fading because opacity target changed
void win_start_fade(session_t *, win **); void win_start_fade(session_t *, win **);
@ -335,8 +337,8 @@ void win_update_bounding_shape(session_t *ps, win *w);
* Note w->shadow and shadow geometry must be correct before calling this * Note w->shadow and shadow geometry must be correct before calling this
* function. * function.
*/ */
void win_extents(win *w, region_t *res); void win_extents(const win *w, region_t *res);
region_t win_extents_by_val(win *w); region_t win_extents_by_val(const win *w);
/** /**
* Add a window to damaged area. * Add a window to damaged area.
* *
@ -349,8 +351,8 @@ void add_damage_from_win(session_t *ps, win *w);
* *
* Return region in global coordinates. * Return region in global coordinates.
*/ */
void win_get_region_noframe_local(win *w, region_t *); void win_get_region_noframe_local(const win *w, region_t *);
region_t win_get_region_noframe_local_by_val(win *w); region_t win_get_region_noframe_local_by_val(const win *w);
/** /**
* Retrieve frame extents from a window. * Retrieve frame extents from a window.
*/ */
@ -370,7 +372,7 @@ void
win_check_fade_finished(session_t *ps, win **_w); win_check_fade_finished(session_t *ps, win **_w);
// Stop receiving events (except ConfigureNotify, XXX why?) from a window // Stop receiving events (except ConfigureNotify, XXX why?) from a window
void win_ev_stop(session_t *ps, win *w); void win_ev_stop(session_t *ps, const win *w);
/// Skip the current in progress fading of window, /// Skip the current in progress fading of window,
/// transition the window straight to its end state /// transition the window straight to its end state
@ -387,10 +389,10 @@ win_get_leader(session_t *ps, win *w) {
} }
/// check if window has ARGB visual /// check if window has ARGB visual
bool attr_const win_has_alpha(const win *w); bool attr_pure win_has_alpha(const win *w);
/// check if reg_ignore_valid is true for all windows above us /// check if reg_ignore_valid is true for all windows above us
bool win_is_region_ignore_valid(session_t *ps, win *w); bool attr_pure win_is_region_ignore_valid(session_t *ps, const win *w);
/// Free all resources in a struct win /// Free all resources in a struct win
void free_win_res(session_t *ps, win *w); void free_win_res(session_t *ps, win *w);