Add option to debug geometry (set env var DEBUG_GEOMETRY) (issue #583)
This commit is contained in:
parent
95a9e8a82e
commit
fc56e48781
12 changed files with 297 additions and 101 deletions
|
@ -58,6 +58,7 @@ gboolean battery_found;
|
|||
|
||||
void battery_init_fonts();
|
||||
char *battery_get_tooltip(void *obj);
|
||||
void battery_dump_geometry(void *obj, int indent);
|
||||
|
||||
void default_battery()
|
||||
{
|
||||
|
@ -382,6 +383,23 @@ void draw_battery(void *obj, cairo_t *c)
|
|||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
void battery_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
Battery *battery = obj;
|
||||
fprintf(stderr,
|
||||
"%*sText 1: y = %d, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
battery->bat1_posy,
|
||||
buf_bat_percentage);
|
||||
fprintf(stderr,
|
||||
"%*sText 2: y = %d, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
battery->bat2_posy,
|
||||
buf_bat_time);
|
||||
}
|
||||
|
||||
char *battery_get_tooltip(void *obj)
|
||||
{
|
||||
return battery_os_tooltip();
|
||||
|
|
|
@ -55,6 +55,7 @@ static timeout *clock_timeout;
|
|||
|
||||
void clock_init_fonts();
|
||||
char *clock_get_tooltip(void *obj);
|
||||
void clock_dump_geometry(void *obj, int indent);
|
||||
|
||||
void default_clock()
|
||||
{
|
||||
|
@ -188,6 +189,7 @@ void init_clock_panel(void *p)
|
|||
clock->area._draw_foreground = draw_clock;
|
||||
clock->area.size_mode = LAYOUT_FIXED;
|
||||
clock->area._resize = resize_clock;
|
||||
clock->area._dump_geometry = clock_dump_geometry;
|
||||
// check consistency
|
||||
if (!time1_format)
|
||||
return;
|
||||
|
@ -334,6 +336,26 @@ void draw_clock(void *obj, cairo_t *c)
|
|||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
void clock_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
Clock *clock = (Clock *)obj;
|
||||
fprintf(stderr,
|
||||
"%*sText 1: y = %d, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
clock->time1_posy,
|
||||
buf_time);
|
||||
if (time2_format) {
|
||||
fprintf(stderr,
|
||||
"%*sText 2: y = %d, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
clock->time2_posy,
|
||||
buf_date);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
char *clock_get_tooltip(void *obj)
|
||||
{
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
void execp_timer_callback(void *arg);
|
||||
char *execp_get_tooltip(void *obj);
|
||||
void execp_init_fonts();
|
||||
void execp_dump_geometry(void *obj, int indent);
|
||||
|
||||
void default_execp()
|
||||
{
|
||||
|
@ -157,7 +158,11 @@ void init_execp_panel(void *p)
|
|||
execp->area.paddingxlr = execp->backend->paddingxlr;
|
||||
execp->area.parent = panel;
|
||||
execp->area.panel = panel;
|
||||
snprintf(execp->area.name, sizeof(execp->area.name), "Execp %s", execp->backend->command ? execp->backend->command : "null");
|
||||
execp->area._dump_geometry = execp_dump_geometry;
|
||||
snprintf(execp->area.name,
|
||||
sizeof(execp->area.name),
|
||||
"Execp %s",
|
||||
execp->backend->command ? execp->backend->command : "null");
|
||||
execp->area._draw_foreground = draw_execp;
|
||||
execp->area.size_mode = LAYOUT_FIXED;
|
||||
execp->area._resize = resize_execp;
|
||||
|
@ -321,8 +326,8 @@ gboolean resize_execp(void *obj)
|
|||
&txt_width,
|
||||
panel->area.height,
|
||||
!text_next_line
|
||||
? execp->area.width - icon_w - (icon_w ? interior_padding : 0) -
|
||||
2 * horiz_padding - left_right_border_width(&execp->area)
|
||||
? execp->area.width - icon_w - (icon_w ? interior_padding : 0) - 2 * horiz_padding -
|
||||
left_right_border_width(&execp->area)
|
||||
: execp->area.width - 2 * horiz_padding - left_right_border_width(&execp->area),
|
||||
execp->backend->text,
|
||||
strlen(execp->backend->text),
|
||||
|
@ -348,7 +353,8 @@ gboolean resize_execp(void *obj)
|
|||
new_size = txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area);
|
||||
new_size = MAX(new_size, icon_h + 2 * vert_padding + top_bottom_border_width(&execp->area));
|
||||
} else {
|
||||
new_size = icon_h + interior_padding + txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area);
|
||||
new_size =
|
||||
icon_h + interior_padding + txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area);
|
||||
}
|
||||
if (new_size != execp->area.height) {
|
||||
execp->area.height = new_size;
|
||||
|
@ -429,6 +435,35 @@ void draw_execp(void *obj, cairo_t *c)
|
|||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
void execp_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
Execp *execp = obj;
|
||||
|
||||
if (execp->backend->has_icon && execp->backend->icon) {
|
||||
Imlib_Image tmp = imlib_context_get_image();
|
||||
imlib_context_set_image(execp->backend->icon);
|
||||
fprintf(stderr,
|
||||
"%*sIcon: x = %d, y = %d, w = %d\n",
|
||||
indent,
|
||||
"",
|
||||
execp->frontend->iconx,
|
||||
execp->frontend->icony,
|
||||
imlib_image_get_width(),
|
||||
imlib_image_get_height());
|
||||
if (tmp)
|
||||
imlib_context_set_image(tmp);
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%*sText: x = %d, y = %d, w = %d, h = %d, align = %s, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
execp->frontend->textx,
|
||||
execp->frontend->texty,
|
||||
execp->frontend->textw,
|
||||
execp->backend->centered ? "center" : "left",
|
||||
execp->backend->text);
|
||||
}
|
||||
|
||||
void execp_action(void *obj, int button, int x, int y)
|
||||
{
|
||||
Execp *execp = obj;
|
||||
|
|
|
@ -56,6 +56,7 @@ Background *launcher_icon_bg;
|
|||
|
||||
Imlib_Image scale_icon(Imlib_Image original, int icon_size);
|
||||
void free_icon(Imlib_Image icon);
|
||||
void launcher_icon_dump_geometry(void *obj, int indent);
|
||||
|
||||
void default_launcher()
|
||||
{
|
||||
|
@ -346,6 +347,17 @@ void draw_launcher_icon(void *obj, cairo_t *c)
|
|||
render_image(launcherIcon->area.pix, 0, 0);
|
||||
}
|
||||
|
||||
void launcher_icon_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
LauncherIcon *launcherIcon = (LauncherIcon *)obj;
|
||||
fprintf(stderr,
|
||||
"%*sIcon: w = h = %d, name = %s\n",
|
||||
indent,
|
||||
"",
|
||||
launcherIcon->icon_size,
|
||||
launcherIcon->icon_name);
|
||||
}
|
||||
|
||||
Imlib_Image scale_icon(Imlib_Image original, int icon_size)
|
||||
{
|
||||
Imlib_Image icon_scaled;
|
||||
|
@ -468,6 +480,7 @@ void launcher_load_icons(Launcher *launcher)
|
|||
launcherIcon->area.bg = launcher_icon_bg;
|
||||
launcherIcon->area.on_screen = TRUE;
|
||||
launcherIcon->area._on_change_layout = launcher_icon_on_change_layout;
|
||||
launcherIcon->area._dump_geometry = launcher_icon_dump_geometry;
|
||||
if (launcher_tooltip_enabled) {
|
||||
launcherIcon->area._get_tooltip_text = launcher_icon_get_tooltip_text;
|
||||
} else {
|
||||
|
|
|
@ -55,6 +55,7 @@ gboolean panel_horizontal;
|
|||
gboolean panel_refresh;
|
||||
gboolean task_dragged;
|
||||
char *panel_window_name = NULL;
|
||||
gboolean debug_geometry;
|
||||
|
||||
gboolean panel_autohide;
|
||||
int panel_autohide_show_timeout;
|
||||
|
@ -942,6 +943,8 @@ void autohide_trigger_hide(Panel *p)
|
|||
void render_panel(Panel *panel)
|
||||
{
|
||||
relayout(&panel->area);
|
||||
if (debug_geometry)
|
||||
area_dump_geometry(&panel->area, 0);
|
||||
draw_tree(&panel->area);
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ extern Imlib_Image default_icon;
|
|||
#define DEFAULT_FONT "sans 10"
|
||||
extern char *default_font;
|
||||
extern XSettingsClient *xsettings_client;
|
||||
extern gboolean debug_geometry;
|
||||
|
||||
typedef struct Panel {
|
||||
Area area;
|
||||
|
|
|
@ -65,6 +65,8 @@ const int slow_resize_period = 5000;
|
|||
const int min_bad_resize_events = 3;
|
||||
const int max_bad_resize_events = 10;
|
||||
|
||||
void systray_dump_geometry(void *obj, int indent);
|
||||
|
||||
void default_systray()
|
||||
{
|
||||
systray_enabled = 0;
|
||||
|
@ -114,6 +116,7 @@ void init_systray_panel(void *p)
|
|||
Panel *panel = (Panel *)p;
|
||||
systray.area.parent = panel;
|
||||
systray.area.panel = panel;
|
||||
systray.area._dump_geometry = systray_dump_geometry;
|
||||
snprintf(systray.area.name, sizeof(systray.area.name), "Systray");
|
||||
if (!systray.area.bg)
|
||||
systray.area.bg = &g_array_index(backgrounds, Background, 0);
|
||||
|
@ -208,6 +211,29 @@ void draw_systray(void *obj, cairo_t *c)
|
|||
refresh_systray = TRUE;
|
||||
}
|
||||
|
||||
void systray_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
Systray *tray = (Systray *)obj;
|
||||
|
||||
fprintf(stderr,
|
||||
"%*sIcons:\n",
|
||||
indent,
|
||||
"");
|
||||
indent += 2;
|
||||
for (GSList *l = tray->list_icons; l; l = l->next) {
|
||||
TrayWindow *traywin = (TrayWindow *)l->data;
|
||||
fprintf(stderr,
|
||||
"%*sIcon: x = %d, y = %d, w = %d, h = %d, name = %s\n",
|
||||
indent,
|
||||
"",
|
||||
traywin->x,
|
||||
traywin->y,
|
||||
traywin->width,
|
||||
traywin->height,
|
||||
traywin->name);
|
||||
}
|
||||
}
|
||||
|
||||
void on_change_systray(void *obj)
|
||||
{
|
||||
if (systray_profile)
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
timeout *urgent_timeout;
|
||||
GSList *urgent_list;
|
||||
|
||||
void task_dump_geometry(void *obj, int indent);
|
||||
|
||||
char *task_get_tooltip(void *obj)
|
||||
{
|
||||
Task *t = (Task *)obj;
|
||||
|
@ -68,6 +70,7 @@ Task *add_task(Window win)
|
|||
snprintf(task_template.area.name, sizeof(task_template.area.name), "Task %d", (int)win);
|
||||
task_template.area.has_mouse_over_effect = panel_config.mouse_effects;
|
||||
task_template.area.has_mouse_press_effect = panel_config.mouse_effects;
|
||||
task_template.area._dump_geometry = task_dump_geometry;
|
||||
task_template.area._is_under_mouse = full_width_area_is_under_mouse;
|
||||
task_template.win = win;
|
||||
task_template.desktop = get_window_desktop(win);
|
||||
|
@ -83,7 +86,11 @@ Task *add_task(Window win)
|
|||
}
|
||||
task_update_title(&task_template);
|
||||
task_update_icon(&task_template);
|
||||
snprintf(task_template.area.name, sizeof(task_template.area.name), "Task %d %s", (int)win, task_template.title ? task_template.title : "null");
|
||||
snprintf(task_template.area.name,
|
||||
sizeof(task_template.area.name),
|
||||
"Task %d %s",
|
||||
(int)win,
|
||||
task_template.title ? task_template.title : "null");
|
||||
|
||||
// fprintf(stderr, "%s %d: win = %ld, task = %s\n", __FUNCTION__, __LINE__, win, task_template.title ?
|
||||
// task_template.title : "??");
|
||||
|
@ -99,6 +106,7 @@ Task *add_task(Window win)
|
|||
memcpy(&task_instance->area, &panels[monitor].g_task.area, sizeof(Area));
|
||||
task_instance->area.has_mouse_over_effect = panel_config.mouse_effects;
|
||||
task_instance->area.has_mouse_press_effect = panel_config.mouse_effects;
|
||||
task_instance->area._dump_geometry = task_dump_geometry;
|
||||
task_instance->area._is_under_mouse = full_width_area_is_under_mouse;
|
||||
task_instance->win = task_template.win;
|
||||
task_instance->desktop = task_template.desktop;
|
||||
|
@ -361,15 +369,14 @@ void draw_task_icon(Task *task, int text_width)
|
|||
return;
|
||||
|
||||
// Find pos
|
||||
int pos_x;
|
||||
Panel *panel = (Panel *)task->area.panel;
|
||||
if (panel->g_task.centered) {
|
||||
if (panel->g_task.has_text)
|
||||
pos_x = (task->area.width - text_width - panel->g_task.icon_size1) / 2;
|
||||
task->_icon_x = (task->area.width - text_width - panel->g_task.icon_size1) / 2;
|
||||
else
|
||||
pos_x = (task->area.width - panel->g_task.icon_size1) / 2;
|
||||
task->_icon_x = (task->area.width - panel->g_task.icon_size1) / 2;
|
||||
} else {
|
||||
pos_x = left_border_width(&task->area) + task->area.paddingxlr;
|
||||
task->_icon_x = left_border_width(&task->area) + task->area.paddingxlr;
|
||||
}
|
||||
|
||||
// Render
|
||||
|
@ -388,14 +395,8 @@ void draw_task_icon(Task *task, int text_width)
|
|||
}
|
||||
|
||||
imlib_context_set_image(image);
|
||||
render_image(task->area.pix, pos_x, (task->area.height - panel->g_task.icon_size1) / 2);
|
||||
if (0) {
|
||||
fprintf(stderr, "Task icon size: %d %d pos %d %d\n", imlib_image_get_width(), imlib_image_get_height(), pos_x, panel->g_task.icon_posy);
|
||||
fprintf(stderr, "Task max size : %d %d\n", panel->g_task.maximum_width, panel->g_task.maximum_height);
|
||||
fprintf(stderr, "Task area size: %d %d\n", task->area.width, task->area.height);
|
||||
fprintf(stderr, "Task border : %d\n", left_border_width(&task->area));
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
task->_icon_y = (task->area.height - panel->g_task.icon_size1) / 2;
|
||||
render_image(task->area.pix, task->_icon_x, task->_icon_y);
|
||||
}
|
||||
|
||||
void draw_task(void *obj, cairo_t *c)
|
||||
|
@ -403,7 +404,7 @@ void draw_task(void *obj, cairo_t *c)
|
|||
Task *task = (Task *)obj;
|
||||
Panel *panel = (Panel *)task->area.panel;
|
||||
|
||||
int text_width = 0;
|
||||
task->_text_width = 0;
|
||||
if (panel->g_task.has_text) {
|
||||
PangoLayout *layout = pango_cairo_create_layout(c);
|
||||
pango_layout_set_font_description(layout, panel->g_task.font_desc);
|
||||
|
@ -419,18 +420,41 @@ void draw_task(void *obj, cairo_t *c)
|
|||
else
|
||||
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
|
||||
|
||||
int text_height;
|
||||
pango_layout_get_pixel_size(layout, &text_width, &text_height);
|
||||
double text_posy = (panel->g_task.area.height - text_height) / 2.0;
|
||||
pango_layout_get_pixel_size(layout, &task->_text_width, &task->_text_height);
|
||||
task->_text_posy = (panel->g_task.area.height - task->_text_height) / 2.0;
|
||||
|
||||
Color *config_text = &panel->g_task.font[task->current_state];
|
||||
draw_text(layout, c, panel->g_task.text_posx, text_posy, config_text, panel->font_shadow);
|
||||
draw_text(layout, c, panel->g_task.text_posx, task->_text_posy, config_text, panel->font_shadow);
|
||||
|
||||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
if (panel->g_task.has_icon)
|
||||
draw_task_icon(task, text_width);
|
||||
draw_task_icon(task, task->_text_width);
|
||||
}
|
||||
|
||||
void task_dump_geometry(void *obj, int indent)
|
||||
{
|
||||
Task *task = (Task *)obj;
|
||||
Panel *panel = (Panel *)task->area.panel;
|
||||
|
||||
fprintf(stderr,
|
||||
"%*sText: x = %d, y = %d, w = %d, h = %d, align = %s, text = %s\n",
|
||||
indent,
|
||||
"",
|
||||
(int)panel->g_task.text_posx,
|
||||
(int)task->_text_posy,
|
||||
task->_text_width,
|
||||
task->_text_height,
|
||||
panel->g_task.centered ? "center" : "left",
|
||||
task->title);
|
||||
fprintf(stderr,
|
||||
"%*sIcon: x = %d, y = %d, w = h = %d\n",
|
||||
indent,
|
||||
"",
|
||||
task->_icon_x,
|
||||
task->_icon_y,
|
||||
panel->g_task.icon_size1);
|
||||
}
|
||||
|
||||
void on_change_task(void *obj)
|
||||
|
|
|
@ -67,6 +67,11 @@ typedef struct Task {
|
|||
int win_w;
|
||||
int win_h;
|
||||
struct timespec last_activation_time;
|
||||
int _text_width;
|
||||
int _text_height;
|
||||
double _text_posy;
|
||||
int _icon_x;
|
||||
int _icon_y;
|
||||
} Task;
|
||||
|
||||
extern timeout *urgent_timeout;
|
||||
|
|
|
@ -372,6 +372,8 @@ void init(int argc, char *argv[])
|
|||
sigaction(SIGABRT, &sa_crash, 0);
|
||||
sigaction(SIGSYS, &sa_crash, 0);
|
||||
#endif
|
||||
|
||||
debug_geometry = getenv("DEBUG_GEOMETRY") != NULL;
|
||||
}
|
||||
|
||||
static int sn_pipe_valid = 0;
|
||||
|
|
|
@ -177,7 +177,8 @@ void relayout_dynamic(Area *a, int level)
|
|||
children_size += (l == a->children) ? 0 : a->paddingx;
|
||||
}
|
||||
|
||||
int pos = (panel_horizontal ? a->posx + left_border_width(a) : a->posy + top_border_width(a)) + a->paddingxlr;
|
||||
int pos =
|
||||
(panel_horizontal ? a->posx + left_border_width(a) : a->posy + top_border_width(a)) + a->paddingxlr;
|
||||
pos += ((panel_horizontal ? a->width : a->height) - children_size) / 2;
|
||||
|
||||
for (GList *l = a->children; l; l = l->next) {
|
||||
|
@ -772,3 +773,44 @@ int top_bottom_bg_border_width(Background *bg)
|
|||
{
|
||||
return top_bg_border_width(bg) + bottom_bg_border_width(bg);
|
||||
}
|
||||
|
||||
void area_dump_geometry(Area *area, int indent)
|
||||
{
|
||||
fprintf(stderr, "%*s%s:\n", indent, "", area->name);
|
||||
indent += 2;
|
||||
if (!area->on_screen) {
|
||||
fprintf(stderr, "%*shidden\n", indent, "");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%*sBox: x = %d, y = %d, w = %d, h = %d\n",
|
||||
indent,
|
||||
"",
|
||||
area->posx,
|
||||
area->posy,
|
||||
area->width,
|
||||
area->height);
|
||||
fprintf(stderr,
|
||||
"%*sBorder: left = %d, right = %d, top = %d, bottom = %d\n",
|
||||
indent,
|
||||
"",
|
||||
left_border_width(area),
|
||||
right_border_width(area),
|
||||
top_border_width(area),
|
||||
bottom_border_width(area));
|
||||
fprintf(stderr,
|
||||
"%*sPadding: left = right = %d, top = bottom = %d, spacing = %d\n",
|
||||
indent,
|
||||
"",
|
||||
area->paddingxlr,
|
||||
area->paddingy,
|
||||
area->paddingx);
|
||||
if (area->_dump_geometry)
|
||||
area->_dump_geometry(area, indent);
|
||||
if (area->children) {
|
||||
fprintf(stderr, "%*sChildren:\n", indent, "");
|
||||
indent += 2;
|
||||
for (GList *l = area->children; l; l = l->next)
|
||||
area_dump_geometry((Area *)l->data, indent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,6 +230,9 @@ typedef struct Area {
|
|||
// Returns true if the Area handles a mouse event at the given x, y coordinates relative to the window.
|
||||
// Leave this to NULL to use a default implementation.
|
||||
gboolean (*_is_under_mouse)(void *obj, int x, int y);
|
||||
|
||||
// Prints the geometry of the object on stderr, with left indentation of indent spaces.
|
||||
void (*_dump_geometry)(void *obj, int indent);
|
||||
} Area;
|
||||
|
||||
// Initializes the Background member to default values.
|
||||
|
@ -306,6 +309,8 @@ gboolean area_is_under_mouse(void *obj, int x, int y);
|
|||
// they are outside the drawing area of the button.
|
||||
gboolean full_width_area_is_under_mouse(void *obj, int x, int y);
|
||||
|
||||
void area_dump_geometry(Area *area, int indent);
|
||||
|
||||
void mouse_over(Area *area, int pressed);
|
||||
void mouse_out();
|
||||
|
||||
|
|
Loading…
Reference in a new issue