Commit fc56e487 authored by o9000's avatar o9000

Add option to debug geometry (set env var DEBUG_GEOMETRY) (issue #583)

parent 95a9e8a8
......@@ -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));
......
This diff is collapsed.
......@@ -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;
......@@ -303,7 +311,7 @@ void task_update_icon(Task *task)
int w = imlib_image_get_width();
int h = imlib_image_get_height();
Imlib_Image orig_image =
imlib_create_cropped_scaled_image(0, 0, w, h, panel->g_task.icon_size1, panel->g_task.icon_size1);
imlib_create_cropped_scaled_image(0, 0, w, h, panel->g_task.icon_size1, panel->g_task.icon_size1);
imlib_free_image();
imlib_context_set_image(orig_image);
......@@ -317,22 +325,22 @@ void task_update_icon(Task *task)
if (panel->g_task.alpha[k] != 100 || panel->g_task.saturation[k] != 0 || panel->g_task.brightness[k] != 0) {
data32 = imlib_image_get_data();
adjust_asb(data32,
task->icon_width,
task->icon_height,
panel->g_task.alpha[k] / 100.0,
panel->g_task.saturation[k] / 100.0,
panel->g_task.brightness[k] / 100.0);
task->icon_width,
task->icon_height,
panel->g_task.alpha[k] / 100.0,
panel->g_task.saturation[k] / 100.0,
panel->g_task.brightness[k] / 100.0);
imlib_image_put_back_data(data32);
}
if (panel_config.mouse_effects) {
task->icon_hover[k] = adjust_icon(task->icon[k],
panel_config.mouse_over_alpha,
panel_config.mouse_over_saturation,
panel_config.mouse_over_brightness);
panel_config.mouse_over_alpha,
panel_config.mouse_over_saturation,
panel_config.mouse_over_brightness);
task->icon_press[k] = adjust_icon(task->icon[k],
panel_config.mouse_pressed_alpha,
panel_config.mouse_pressed_saturation,
panel_config.mouse_pressed_brightness);
panel_config.mouse_pressed_alpha,
panel_config.mouse_pressed_saturation,
panel_config.mouse_pressed_brightness);
}
}
imlib_context_set_image(orig_image);
......@@ -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)
......@@ -440,13 +464,13 @@ void on_change_task(void *obj)
long value[] = {panel->posx + task->area.posx, panel->posy + task->area.posy, task->area.width, task->area.height};
XChangeProperty(server.display,
task->win,
server.atom._NET_WM_ICON_GEOMETRY,
XA_CARDINAL,
32,
PropModeReplace,
(unsigned char *)value,
4);
task->win,
server.atom._NET_WM_ICON_GEOMETRY,
XA_CARDINAL,
32,
PropModeReplace,
(unsigned char *)value,
4);
}
Task *find_active_task(Task *current_task)
......@@ -579,7 +603,7 @@ void set_task_state(Task *task, TaskState state)
}
}
if (get_window_monitor(task->win) != ((Panel *)task->area.panel)->monitor &&
(hide_task_diff_monitor || num_panels > 1)) {
(hide_task_diff_monitor || num_panels > 1)) {
hide = TRUE;
}
if ((!hide) != task1->area.on_screen) {
......
......@@ -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) {
......@@ -459,10 +460,10 @@ void draw_background(Area *a, cairo_t *c)
a->bg->fill_color.alpha);
// Not sure about this
draw_rect(c,
left_border_width(a),
top_border_width(a),
a->width - left_right_border_width(a),
a->height - top_bottom_border_width(a),
left_border_width(a),
top_border_width(a),
a->width - left_right_border_width(a),
a->height - top_bottom_border_width(a),
a->bg->border.radius - a->bg->border.width / 1.571);
cairo_fill(c);
......@@ -491,10 +492,10 @@ void draw_background(Area *a, cairo_t *c)
a->bg->border.color.rgb[2],
a->bg->border.color.alpha);
draw_rect_on_sides(c,
left_border_width(a) / 2.,
top_border_width(a) / 2.,
a->width - left_right_border_width(a) / 2.,
a->height - top_bottom_border_width(a) / 2.,
left_border_width(a) / 2.,
top_border_width(a) / 2.,
a->width - left_right_border_width(a) / 2.,
a->height - top_bottom_border_width(a) / 2.,
a->bg->border.radius,
a->bg->border.mask);
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment