+/**
+ * Called when a floating window is created or resized.
+ * This function resizes the window if its size is higher or lower than the
+ * configured maximum/minimum size, respectively.
+ *
+ */
+void floating_check_size(Con *floating_con) {
+ /* Define reasonable minimal and maximal sizes for floating windows */
+ const int floating_sane_min_height = 50;
+ const int floating_sane_min_width = 75;
+ Rect floating_sane_max_dimensions;
+ Con *focused_con = con_descend_focused(floating_con);
+
+ /* obey size increments */
+ if (focused_con->height_increment || focused_con->width_increment) {
+ Rect border_rect = con_border_style_rect(focused_con);
+
+ /* We have to do the opposite calculations that render_con() do
+ * to get the exact size we want. */
+ border_rect.width = -border_rect.width;
+ border_rect.width += 2 * focused_con->border_width;
+ border_rect.height = -border_rect.height;
+ border_rect.height += 2 * focused_con->border_width;
+ if (con_border_style(focused_con) == BS_NORMAL)
+ border_rect.height += render_deco_height();
+
+ if (focused_con->height_increment &&
+ floating_con->rect.height >= focused_con->base_height + border_rect.height) {
+ floating_con->rect.height -= focused_con->base_height + border_rect.height;
+ floating_con->rect.height -= floating_con->rect.height % focused_con->height_increment;
+ floating_con->rect.height += focused_con->base_height + border_rect.height;
+ }
+
+ if (focused_con->width_increment &&
+ floating_con->rect.width >= focused_con->base_width + border_rect.width) {
+ floating_con->rect.width -= focused_con->base_width + border_rect.width;
+ floating_con->rect.width -= floating_con->rect.width % focused_con->width_increment;
+ floating_con->rect.width += focused_con->base_width + border_rect.width;
+ }
+ }
+
+ /* Unless user requests otherwise (-1), ensure width/height do not exceed
+ * configured maxima or, if unconfigured, limit to combined width of all
+ * outputs */
+ if (config.floating_minimum_height != -1) {
+ if (config.floating_minimum_height == 0)
+ floating_con->rect.height = max(floating_con->rect.height, floating_sane_min_height);
+ else
+ floating_con->rect.height = max(floating_con->rect.height, config.floating_minimum_height);
+ }
+ if (config.floating_minimum_width != -1) {
+ if (config.floating_minimum_width == 0)
+ floating_con->rect.width = max(floating_con->rect.width, floating_sane_min_width);
+ else
+ floating_con->rect.width = max(floating_con->rect.width, config.floating_minimum_width);
+ }
+
+ /* Unless user requests otherwise (-1), raise the width/height to
+ * reasonable minimum dimensions */
+ floating_sane_max_dimensions = total_outputs_dimensions();
+ if (config.floating_maximum_height != -1) {
+ if (config.floating_maximum_height == 0)
+ floating_con->rect.height = min(floating_con->rect.height, floating_sane_max_dimensions.height);
+ else
+ floating_con->rect.height = min(floating_con->rect.height, config.floating_maximum_height);
+ }
+ if (config.floating_maximum_width != -1) {
+ if (config.floating_maximum_width == 0)
+ floating_con->rect.width = min(floating_con->rect.width, floating_sane_max_dimensions.width);
+ else
+ floating_con->rect.width = min(floating_con->rect.width, config.floating_maximum_width);
+ }
+}
+