geometry: Use the relevant rounding functions instead of integers
In the case where one want to put the cursor at the middle of the workarea, it is logic to do: x=screen.workarea.x+screen.workasrea.width/2 However, this can cause floating points. This commit move the burden back to the C-API so the Lua placement code doesn't have to add a large number of rounding methods. Given 1 type of rounding cover a vast majority of use cases for each types of coordinates, the C-API can take care of it in peace. For the other corner cases, it is still possible for the Lua code to do the rounding there, but no longer necessary. The convenstions are: 'x' and 'y': use round (move to the closest point) 'width' and 'height': use ceil (to avoid involontary truncating)
This commit is contained in:
parent
d46e11f5e1
commit
9991f9ccc8
|
@ -98,6 +98,8 @@
|
||||||
#include "systray.h"
|
#include "systray.h"
|
||||||
#include "xwindow.h"
|
#include "xwindow.h"
|
||||||
|
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
#include <xcb/xcb_atom.h>
|
#include <xcb/xcb_atom.h>
|
||||||
#include <xcb/shape.h>
|
#include <xcb/shape.h>
|
||||||
#include <cairo-xcb.h>
|
#include <cairo-xcb.h>
|
||||||
|
@ -2538,7 +2540,7 @@ luaA_client_titlebar_ ## name(lua_State *L) \
|
||||||
if (lua_isnil(L, 2)) \
|
if (lua_isnil(L, 2)) \
|
||||||
titlebar_resize(L, 1, c, index, 0); \
|
titlebar_resize(L, 1, c, index, 0); \
|
||||||
else \
|
else \
|
||||||
titlebar_resize(L, 1, c, index, luaA_checkinteger_range(L, 2, 0, MAX_X11_SIZE)); \
|
titlebar_resize(L, 1, c, index, ceil(luaA_checknumber_range(L, 2, 0, MAX_X11_SIZE))); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
|
luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
|
||||||
|
@ -2566,8 +2568,8 @@ luaA_client_geometry(lua_State *L)
|
||||||
area_t geometry;
|
area_t geometry;
|
||||||
|
|
||||||
luaA_checktable(L, 2);
|
luaA_checktable(L, 2);
|
||||||
geometry.x = luaA_getopt_integer_range(L, 2, "x", c->geometry.x, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
geometry.x = round(luaA_getopt_number_range(L, 2, "x", c->geometry.x, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
geometry.y = luaA_getopt_integer_range(L, 2, "y", c->geometry.y, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
geometry.y = round(luaA_getopt_number_range(L, 2, "y", c->geometry.y, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
if(client_isfixed(c))
|
if(client_isfixed(c))
|
||||||
{
|
{
|
||||||
geometry.width = c->geometry.width;
|
geometry.width = c->geometry.width;
|
||||||
|
@ -2575,8 +2577,8 @@ luaA_client_geometry(lua_State *L)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
geometry.width = luaA_getopt_integer_range(L, 2, "width", c->geometry.width, MIN_X11_SIZE, MAX_X11_SIZE);
|
geometry.width = ceil(luaA_getopt_number_range(L, 2, "width", c->geometry.width, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
geometry.height = luaA_getopt_integer_range(L, 2, "height", c->geometry.height, MIN_X11_SIZE, MAX_X11_SIZE);
|
geometry.height = ceil(luaA_getopt_number_range(L, 2, "height", c->geometry.height, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
client_resize(c, geometry, c->size_hints_honor);
|
client_resize(c, geometry, c->size_hints_honor);
|
||||||
|
@ -2600,8 +2602,8 @@ luaA_client_apply_size_hints(lua_State *L)
|
||||||
area_t geometry = c->geometry;
|
area_t geometry = c->geometry;
|
||||||
if(!client_isfixed(c))
|
if(!client_isfixed(c))
|
||||||
{
|
{
|
||||||
geometry.width = luaA_checkinteger_range(L, 2, MIN_X11_SIZE, MAX_X11_SIZE);
|
geometry.width = ceil(luaA_checknumber_range(L, 2, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
geometry.height = luaA_checkinteger_range(L, 3, MIN_X11_SIZE, MAX_X11_SIZE);
|
geometry.height = ceil(luaA_checknumber_range(L, 3, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->size_hints_honor)
|
if (c->size_hints_honor)
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#include "systray.h"
|
#include "systray.h"
|
||||||
#include "xwindow.h"
|
#include "xwindow.h"
|
||||||
|
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
#include <cairo-xcb.h>
|
#include <cairo-xcb.h>
|
||||||
#include <xcb/shape.h>
|
#include <xcb/shape.h>
|
||||||
|
|
||||||
|
@ -407,10 +409,10 @@ luaA_drawin_geometry(lua_State *L)
|
||||||
area_t wingeom;
|
area_t wingeom;
|
||||||
|
|
||||||
luaA_checktable(L, 2);
|
luaA_checktable(L, 2);
|
||||||
wingeom.x = luaA_getopt_integer_range(L, 2, "x", drawin->geometry.x, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
wingeom.x = round(luaA_getopt_number_range(L, 2, "x", drawin->geometry.x, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
wingeom.y = luaA_getopt_integer_range(L, 2, "y", drawin->geometry.y, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
wingeom.y = round(luaA_getopt_number_range(L, 2, "y", drawin->geometry.y, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
wingeom.width = luaA_getopt_integer_range(L, 2, "width", drawin->geometry.width, MIN_X11_SIZE, MAX_X11_SIZE);
|
wingeom.width = ceil(luaA_getopt_number_range(L, 2, "width", drawin->geometry.width, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
wingeom.height = luaA_getopt_integer_range(L, 2, "height", drawin->geometry.height, MIN_X11_SIZE, MAX_X11_SIZE);
|
wingeom.height = ceil(luaA_getopt_number_range(L, 2, "height", drawin->geometry.height, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
|
|
||||||
if(wingeom.width > 0 && wingeom.height > 0)
|
if(wingeom.width > 0 && wingeom.height > 0)
|
||||||
drawin_moveresize(L, 1, wingeom);
|
drawin_moveresize(L, 1, wingeom);
|
||||||
|
@ -427,7 +429,7 @@ LUA_OBJECT_EXPORT_PROPERTY(drawin, drawin_t, visible, lua_pushboolean)
|
||||||
static int
|
static int
|
||||||
luaA_drawin_set_x(lua_State *L, drawin_t *drawin)
|
luaA_drawin_set_x(lua_State *L, drawin_t *drawin)
|
||||||
{
|
{
|
||||||
int x = luaA_checkinteger_range(L, -1, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
int x = round(luaA_checknumber_range(L, -1, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
drawin_moveresize(L, -3, (area_t) { .x = x,
|
drawin_moveresize(L, -3, (area_t) { .x = x,
|
||||||
.y = drawin->geometry.y,
|
.y = drawin->geometry.y,
|
||||||
.width = drawin->geometry.width,
|
.width = drawin->geometry.width,
|
||||||
|
@ -445,7 +447,7 @@ luaA_drawin_get_x(lua_State *L, drawin_t *drawin)
|
||||||
static int
|
static int
|
||||||
luaA_drawin_set_y(lua_State *L, drawin_t *drawin)
|
luaA_drawin_set_y(lua_State *L, drawin_t *drawin)
|
||||||
{
|
{
|
||||||
int y = luaA_checkinteger_range(L, -1, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
int y = round(luaA_checknumber_range(L, -1, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
||||||
.y = y,
|
.y = y,
|
||||||
.width = drawin->geometry.width,
|
.width = drawin->geometry.width,
|
||||||
|
@ -463,7 +465,7 @@ luaA_drawin_get_y(lua_State *L, drawin_t *drawin)
|
||||||
static int
|
static int
|
||||||
luaA_drawin_set_width(lua_State *L, drawin_t *drawin)
|
luaA_drawin_set_width(lua_State *L, drawin_t *drawin)
|
||||||
{
|
{
|
||||||
int width = luaA_checkinteger_range(L, -1, MIN_X11_SIZE, MAX_X11_SIZE);
|
int width = ceil(luaA_checknumber_range(L, -1, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
||||||
.y = drawin->geometry.y,
|
.y = drawin->geometry.y,
|
||||||
.width = width,
|
.width = width,
|
||||||
|
@ -481,7 +483,7 @@ luaA_drawin_get_width(lua_State *L, drawin_t *drawin)
|
||||||
static int
|
static int
|
||||||
luaA_drawin_set_height(lua_State *L, drawin_t *drawin)
|
luaA_drawin_set_height(lua_State *L, drawin_t *drawin)
|
||||||
{
|
{
|
||||||
int height = luaA_checkinteger_range(L, -1, MIN_X11_SIZE, MAX_X11_SIZE);
|
int height = ceil(luaA_checknumber_range(L, -1, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
drawin_moveresize(L, -3, (area_t) { .x = drawin->geometry.x,
|
||||||
.y = drawin->geometry.y,
|
.y = drawin->geometry.y,
|
||||||
.width = drawin->geometry.width,
|
.width = drawin->geometry.width,
|
||||||
|
|
|
@ -476,7 +476,7 @@ window_translate_type(window_type_t type)
|
||||||
static int
|
static int
|
||||||
luaA_window_set_border_width(lua_State *L, window_t *c)
|
luaA_window_set_border_width(lua_State *L, window_t *c)
|
||||||
{
|
{
|
||||||
window_set_border_width(L, -3, luaA_checkinteger_range(L, -1, 0, MAX_X11_SIZE));
|
window_set_border_width(L, -3, round(luaA_checknumber_range(L, -1, 0, MAX_X11_SIZE)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "common/luaclass.h"
|
#include "common/luaclass.h"
|
||||||
#include "objects/button.h"
|
#include "objects/button.h"
|
||||||
#include "strut.h"
|
#include "strut.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
/** Windows type */
|
/** Windows type */
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
6
root.c
6
root.c
|
@ -34,6 +34,8 @@
|
||||||
#include "objects/button.h"
|
#include "objects/button.h"
|
||||||
#include "xwindow.h"
|
#include "xwindow.h"
|
||||||
|
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
#include <xcb/xtest.h>
|
#include <xcb/xtest.h>
|
||||||
#include <xcb/xcb_aux.h>
|
#include <xcb/xcb_aux.h>
|
||||||
#include <cairo-xcb.h>
|
#include <cairo-xcb.h>
|
||||||
|
@ -266,8 +268,8 @@ luaA_root_fake_input(lua_State *L)
|
||||||
{
|
{
|
||||||
type = XCB_MOTION_NOTIFY;
|
type = XCB_MOTION_NOTIFY;
|
||||||
detail = luaA_checkboolean(L, 2); /* relative to the current position or not */
|
detail = luaA_checkboolean(L, 2); /* relative to the current position or not */
|
||||||
x = luaA_checkinteger_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
x = round(luaA_checknumber_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
y = luaA_checkinteger_range(L, 4, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
y = round(luaA_checknumber_range(L, 4, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
9
strut.c
9
strut.c
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "strut.h"
|
#include "strut.h"
|
||||||
#include "luaa.h"
|
#include "luaa.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
/** Push a strut type to a table on stack.
|
/** Push a strut type to a table on stack.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
@ -51,10 +52,10 @@ void
|
||||||
luaA_tostrut(lua_State *L, int idx, strut_t *strut)
|
luaA_tostrut(lua_State *L, int idx, strut_t *strut)
|
||||||
{
|
{
|
||||||
luaA_checktable(L, idx);
|
luaA_checktable(L, idx);
|
||||||
strut->left = luaA_getopt_integer_range(L, idx, "left", strut->left, 0, UINT16_MAX);
|
strut->left = ceil(luaA_getopt_number_range(L, idx, "left", strut->left, 0, UINT16_MAX));
|
||||||
strut->right = luaA_getopt_integer_range(L, idx, "right", strut->right, 0, UINT16_MAX);
|
strut->right = ceil(luaA_getopt_number_range(L, idx, "right", strut->right, 0, UINT16_MAX));
|
||||||
strut->top = luaA_getopt_integer_range(L, idx, "top", strut->top, 0, UINT16_MAX);
|
strut->top = ceil(luaA_getopt_number_range(L, idx, "top", strut->top, 0, UINT16_MAX));
|
||||||
strut->bottom = luaA_getopt_integer_range(L, idx, "bottom", strut->bottom, 0, UINT16_MAX);
|
strut->bottom = ceil(luaA_getopt_number_range(L, idx, "bottom", strut->bottom, 0, UINT16_MAX));
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -325,13 +325,13 @@ luaA_systray(lua_State *L)
|
||||||
{
|
{
|
||||||
size_t bg_len;
|
size_t bg_len;
|
||||||
drawin_t *w = luaA_checkudata(L, 1, &drawin_class);
|
drawin_t *w = luaA_checkudata(L, 1, &drawin_class);
|
||||||
int x = luaA_checkinteger_range(L, 2, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
int x = round(luaA_checknumber_range(L, 2, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
int y = luaA_checkinteger_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE);
|
int y = round(luaA_checknumber_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
||||||
int base_size = luaA_checkinteger_range(L, 4, MIN_X11_SIZE, MAX_X11_SIZE);
|
int base_size = ceil(luaA_checknumber_range(L, 4, MIN_X11_SIZE, MAX_X11_SIZE));
|
||||||
bool horiz = lua_toboolean(L, 5);
|
bool horiz = lua_toboolean(L, 5);
|
||||||
const char *bg = luaL_checklstring(L, 6, &bg_len);
|
const char *bg = luaL_checklstring(L, 6, &bg_len);
|
||||||
bool revers = lua_toboolean(L, 7);
|
bool revers = lua_toboolean(L, 7);
|
||||||
int spacing = luaA_checkinteger_range(L, 8, 0, MAX_X11_COORDINATE);
|
int spacing = ceil(luaA_checknumber_range(L, 8, 0, MAX_X11_COORDINATE));
|
||||||
color_t bg_color;
|
color_t bg_color;
|
||||||
bool force_redraw = false;
|
bool force_redraw = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue