Index: trunk/src_plugins/hid_gtk/gui-config.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-config.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-config.c (revision 2372) @@ -34,6 +34,7 @@ #include #include "gui.h" +#include "win_place.h" #include "hid.h" #include "gtkhid.h" @@ -163,19 +164,30 @@ return (r == CFR_DESIGN) || (r == CFR_PROJECT); } -#define just_loaded_geo(path_prefix) (just_loaded(path_prefix "_width") || just_loaded(path_prefix "_height")) +#define path_prefix "plugins/hid_gtk/window_geometry/" +#define did_just_load_geo(win, id) \ + if (just_loaded(path_prefix #win "_width") || just_loaded(path_prefix #win "_height") \ + || just_loaded(path_prefix #win "_x") || just_loaded(path_prefix #win "_y")) { \ + hid_gtk_wgeo.win ## _width = conf_hid_gtk.plugins.hid_gtk.window_geometry.win ## _width; \ + hid_gtk_wgeo.win ## _height = conf_hid_gtk.plugins.hid_gtk.window_geometry.win ## _height; \ + hid_gtk_wgeo.win ## _x = conf_hid_gtk.plugins.hid_gtk.window_geometry.win ## _x; \ + hid_gtk_wgeo.win ## _y = conf_hid_gtk.plugins.hid_gtk.window_geometry.win ## _y; \ + wplc_place(id, NULL); \ + } void ghid_conf_load_post_wgeo(void *user_data, int argc, event_arg_t * argv[]) { - if (just_loaded_geo("plugins/hid_gtk/window_geometry/top")) { - hid_gtk_wgeo.top_width = conf_hid_gtk.plugins.hid_gtk.window_geometry.top_width; - hid_gtk_wgeo.top_height = conf_hid_gtk.plugins.hid_gtk.window_geometry.top_height; -/* printf("Resize top: %d %d\n", hid_gtk_wgeo.top_width, hid_gtk_wgeo.top_height);*/ - gtk_window_resize(GTK_WINDOW(gport->top_window), hid_gtk_wgeo.top_width, hid_gtk_wgeo.top_height); - } + did_just_load_geo(top, WPLC_TOP); + did_just_load_geo(log, WPLC_LOG); + did_just_load_geo(drc, WPLC_DRC); + did_just_load_geo(library, WPLC_LIBRARY); + did_just_load_geo(netlist, WPLC_NETLIST); + did_just_load_geo(keyref, WPLC_KEYREF); + did_just_load_geo(pinout, WPLC_PINOUT); +} +#undef path_prefix -} #undef just_loaded_geo Index: trunk/src_plugins/hid_gtk/gui-drc-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-drc-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-drc-window.c (revision 2372) @@ -36,6 +36,7 @@ #include "undo.h" #include "set.h" #include "gui.h" +#include "win_place.h" #include "gui-drc-window.h" #include "hid_actions.h" @@ -52,14 +53,7 @@ /* Remember user window resizes. */ static gint drc_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, gpointer data) { - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - - hid_gtk_wgeo.drc_width = allocation.width; - hid_gtk_wgeo.drc_height = allocation.height; - hid_gtk_wgeo_update(); - + wplc_config_event(widget, &hid_gtk_wgeo.drc_x, &hid_gtk_wgeo.drc_y, &hid_gtk_wgeo.drc_width, &hid_gtk_wgeo.drc_height); return FALSE; } @@ -777,9 +771,9 @@ g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(drc_close_cb), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + wplc_place(WPLC_DRC, drc_window); + gtk_widget_realize(drc_window); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(drc_window), 10, 10); gtk_widget_show_all(drc_window); } Index: trunk/src_plugins/hid_gtk/gui-keyref-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-keyref-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-keyref-window.c (revision 2372) @@ -31,8 +31,8 @@ #include "config.h" #include "gui.h" +#include "win_place.h" - RCSID("$Id$"); static GtkWidget *keyref_window; @@ -303,13 +303,7 @@ */ static gint keyref_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, gpointer data) { - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - hid_gtk_wgeo.keyref_width = allocation.width; - hid_gtk_wgeo.keyref_height = allocation.height; - hid_gtk_wgeo_update(); - + wplc_config_event(widget, &hid_gtk_wgeo.keyref_x, &hid_gtk_wgeo.keyref_y, &hid_gtk_wgeo.keyref_width, &hid_gtk_wgeo.keyref_height); return FALSE; } Index: trunk/src_plugins/hid_gtk/gui-library-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-library-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-library-window.c (revision 2372) @@ -57,6 +57,7 @@ #include "conf_core.h" #include "gui.h" +#include "win_place.h" #include "global.h" #include "buffer.h" #include "data.h" @@ -88,14 +89,7 @@ static gint library_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, gpointer data) { - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - - hid_gtk_wgeo.library_width = allocation.width; - hid_gtk_wgeo.library_height = allocation.height; - hid_gtk_wgeo_update(); - + wplc_config_event(widget, &hid_gtk_wgeo.library_x, &hid_gtk_wgeo.library_y, &hid_gtk_wgeo.library_width, &hid_gtk_wgeo.library_height); return FALSE; } @@ -159,9 +153,9 @@ gtk_window_set_title(GTK_WINDOW(library_window), _("pcb-rnd Library")); gtk_window_set_wmclass(GTK_WINDOW(library_window), "PCB_Library", "PCB"); + wplc_place(WPLC_LIBRARY, library_window); + gtk_widget_realize(library_window); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(library_window), 10, 10); gtk_editable_select_region(GTK_EDITABLE(GHID_LIBRARY_WINDOW(library_window)->entry_filter), 0, -1); Index: trunk/src_plugins/hid_gtk/gui-log-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-log-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-log-window.c (revision 2372) @@ -33,6 +33,7 @@ #include "conf_core.h" #include "gui.h" +#include "win_place.h" #include "pcb-printf.h" @@ -44,14 +45,7 @@ /* Remember user window resizes. */ static gint log_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, gpointer data) { - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - - hid_gtk_wgeo.log_width = allocation.width; - hid_gtk_wgeo.log_height = allocation.height; - hid_gtk_wgeo_update(); - + wplc_config_event(widget, &hid_gtk_wgeo.log_x, &hid_gtk_wgeo.log_y, &hid_gtk_wgeo.log_width, &hid_gtk_wgeo.log_height); return FALSE; } @@ -94,9 +88,9 @@ g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(log_close_cb), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + wplc_place(WPLC_LOG, log_window); + gtk_widget_realize(log_window); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(log_window), 10, 10); } void ghid_log_window_show(gboolean raise) Index: trunk/src_plugins/hid_gtk/gui-netlist-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-netlist-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-netlist-window.c (revision 2372) @@ -41,6 +41,8 @@ #include "global.h" +#include "win_place.h" + #include "create.h" #include "data.h" #include "draw.h" @@ -620,13 +622,7 @@ */ static gint netlist_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, gpointer data) { - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - - hid_gtk_wgeo.netlist_height = allocation.height; - hid_gtk_wgeo_update(); - + wplc_config_event(widget, &hid_gtk_wgeo.netlist_x, &hid_gtk_wgeo.netlist_y, &hid_gtk_wgeo.netlist_width, &hid_gtk_wgeo.netlist_height); return FALSE; } @@ -765,11 +761,9 @@ g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(netlist_close_cb), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + wplc_place(WPLC_NETLIST, netlist_window); gtk_widget_realize(netlist_window); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(netlist_window), 10, 10); - } void ghid_netlist_window_show(GHidPort * out, gboolean raise) Index: trunk/src_plugins/hid_gtk/gui-pinout-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-pinout-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-pinout-window.c (revision 2372) @@ -34,6 +34,7 @@ #include "global.h" #include "gui.h" +#include "win_place.h" #include "copy.h" #include "data.h" @@ -90,7 +91,6 @@ gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_realize(top_window); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(top_window), 10, 10); + wplc_place(WPLC_PINOUT, top_window); gtk_widget_show_all(top_window); } Index: trunk/src_plugins/hid_gtk/gui-top-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-top-window.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-top-window.c (revision 2372) @@ -97,6 +97,7 @@ #include "gui-icons-mode-buttons.data" #include "gui-icons-misc.data" #include "gui.h" +#include "win_place.h" #include "hid_attrib.h" #include "hid_actions.h" #include "hid_flags.h" @@ -160,20 +161,8 @@ */ static gint top_window_configure_event_cb(GtkWidget * widget, GdkEventConfigure * ev, GHidPort * port) { - GtkAllocation allocation; - gboolean new_w, new_h; + wplc_config_event(widget, &hid_gtk_wgeo.top_x, &hid_gtk_wgeo.top_y, &hid_gtk_wgeo.top_width, &hid_gtk_wgeo.top_height); - gtk_widget_get_allocation(widget, &allocation); - - new_w = (hid_gtk_wgeo.top_width != allocation.width); - new_h = (hid_gtk_wgeo.top_height != allocation.height); - - hid_gtk_wgeo.top_width = allocation.width; - hid_gtk_wgeo.top_height = allocation.height; - - if (new_w || new_h) - hid_gtk_wgeo_update(); - return FALSE; } @@ -1445,10 +1434,8 @@ window = gport->top_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "pcb-rnd"); - gtk_window_set_default_size(GTK_WINDOW(window), hid_gtk_wgeo.top_width, hid_gtk_wgeo.top_height); - if (conf_core.editor.auto_place) - gtk_window_move(GTK_WINDOW(window), 10, 10); + wplc_place(WPLC_TOP, window); gtk_widget_show_all(gport->top_window); ghidgui->creating = TRUE; Index: trunk/src_plugins/hid_gtk/gui-utils.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-utils.c (revision 2371) +++ trunk/src_plugins/hid_gtk/gui-utils.c (revision 2372) @@ -37,6 +37,11 @@ RCSID("$Id$"); +#warning TODO: get this compield in a separate .o + +#include "win_place.c" + + /* Not a gui function, but no better place to put it... */ gboolean dup_string(gchar ** dst, const gchar * src) Index: trunk/src_plugins/hid_gtk/hid_gtk_conf.h =================================================================== --- trunk/src_plugins/hid_gtk/hid_gtk_conf.h (revision 2371) +++ trunk/src_plugins/hid_gtk/hid_gtk_conf.h (revision 2372) @@ -22,36 +22,61 @@ } auto_save_window_geometry; const struct window_geometry { + CFT_INTEGER top_x; + CFT_INTEGER top_y; CFT_INTEGER top_width; CFT_INTEGER top_height; + + CFT_INTEGER log_x; + CFT_INTEGER log_y; CFT_INTEGER log_width; CFT_INTEGER log_height; + + CFT_INTEGER drc_x; + CFT_INTEGER drc_y; CFT_INTEGER drc_width; CFT_INTEGER drc_height; + + CFT_INTEGER library_x; + CFT_INTEGER library_y; CFT_INTEGER library_width; CFT_INTEGER library_height; - CFT_INTEGER netlist_height; + + CFT_INTEGER keyref_x; + CFT_INTEGER keyref_y; CFT_INTEGER keyref_width; CFT_INTEGER keyref_height; + + CFT_INTEGER netlist_x; + CFT_INTEGER netlist_y; + CFT_INTEGER netlist_height; + CFT_INTEGER netlist_width; + + CFT_INTEGER pinout_x; + CFT_INTEGER pinout_y; + CFT_INTEGER pinout_height; + CFT_INTEGER pinout_width; } window_geometry; } hid_gtk; } plugins; } conf_hid_gtk_t; +#define GHID_WGEO1(win, op, ...) \ + op(win ## _x, __VA_ARGS__); \ + op(win ## _y, __VA_ARGS__); \ + op(win ## _width, __VA_ARGS__); \ + op(win ## _height, __VA_ARGS__); + /* Call macro op(field_name, ...) for each window geometry field */ #define GHID_WGEO_ALL(op, ...) \ do { \ - op(top_width, __VA_ARGS__); \ - op(top_height, __VA_ARGS__); \ - op(log_width, __VA_ARGS__); \ - op(log_height, __VA_ARGS__); \ - op(drc_width, __VA_ARGS__); \ - op(drc_height, __VA_ARGS__); \ - op(library_width, __VA_ARGS__); \ - op(library_height, __VA_ARGS__); \ - op(netlist_height, __VA_ARGS__); \ - op(keyref_width, __VA_ARGS__); \ - op(keyref_height, __VA_ARGS__); \ + GHID_WGEO1(top, op, __VA_ARGS__); \ + GHID_WGEO1(log, op, __VA_ARGS__); \ + GHID_WGEO1(drc, op, __VA_ARGS__); \ + GHID_WGEO1(library, op, __VA_ARGS__); \ + GHID_WGEO1(keyref, op, __VA_ARGS__); \ + GHID_WGEO1(netlist, op, __VA_ARGS__); \ + GHID_WGEO1(pinout, op, __VA_ARGS__); \ } while(0) typedef struct window_geometry window_geometry_t; Index: trunk/src_plugins/hid_gtk/win_place.c =================================================================== --- trunk/src_plugins/hid_gtk/win_place.c (nonexistent) +++ trunk/src_plugins/hid_gtk/win_place.c (revision 2372) @@ -0,0 +1,108 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "win_place.h" + +#define CONF_PREFIX "plugins/hid_gtk/window_geometry/" +static const char *conf_prefix[WPLC_max] = { /* order DOES matter */ + "top_", + "log_", + "drc_", + "library_", + "netlist_", + "keyref_", + "pinout_", + NULL +}; + +static GtkWidget *wplc_windows[WPLC_max]; + +/* true if the given configuration item has exactly one integer value */ +#define HAVE(native) ((native != NULL) && ((native)->used == 1) && ((native)->type == CFN_INTEGER)) + +void wplc_place(wplc_win_t id, GtkWidget *new_win) +{ + char path[128], *pe; + conf_native_t *nx, *ny, *nw, *nh; + GtkWidget *win; + + if (!conf_core.editor.auto_place) + return; /* feature disabled */ + + if ((id < 0) || (id >= WPLC_max)) + return; /* invalid window */ + + /* build base path for the specific window */ + pe = path; + strcpy(pe, CONF_PREFIX); pe += strlen(CONF_PREFIX); + strcpy(pe, conf_prefix[id]); pe += strlen(conf_prefix[id]); + + /* query each parameter */ + strcpy(pe, "height"); nh = conf_get_field(path); + strcpy(pe, "width"); nw = conf_get_field(path); + strcpy(pe, "x"); nx = conf_get_field(path); + strcpy(pe, "y"); ny = conf_get_field(path); + + if (new_win != NULL) { + wplc_windows[id] = new_win; + win = new_win; + /* for new windows set hint */ + if (HAVE(nw) && HAVE(nh)) + gtk_window_set_default_size(GTK_WINDOW(win), nw->val.integer[0], nh->val.integer[0]); + if (HAVE(nx) && HAVE(ny)) + gtk_window_move(GTK_WINDOW(win), nx->val.integer[0], ny->val.integer[0]); + else + gtk_window_move(GTK_WINDOW(win), 10, 10); /* original behaviour */ + } + else { + win = wplc_windows[id]; + if (HAVE(nw) && HAVE(nh)) + gtk_window_resize(GTK_WINDOW(win), nw->val.integer[0], nh->val.integer[0]); + if (HAVE(nx) && HAVE(ny)) + gtk_window_move(GTK_WINDOW(win), nx->val.integer[0], ny->val.integer[0]); + } +} +#undef HAVE + +void wplc_config_event(GtkWidget *win, long *cx, long *cy, long *cw, long *ch) +{ + GtkAllocation allocation; + gboolean new_w, new_h, new_x, new_y; + + gtk_widget_get_allocation(win, &allocation); + + /* For whatever reason, get_allocation doesn't set these. Gtk. */ + gtk_window_get_position(GTK_WINDOW(win), &allocation.x, &allocation.y); + + new_w = (*cw != allocation.width); + new_h = (*ch != allocation.height); + new_x = (*cx != allocation.x); + new_y = (*cy != allocation.y); + + *cx = allocation.x; + *cy = allocation.y; + *cw = allocation.width; + *ch = allocation.height; + + if (new_w || new_h || new_x || new_y) + hid_gtk_wgeo_update(); +} Index: trunk/src_plugins/hid_gtk/win_place.h =================================================================== --- trunk/src_plugins/hid_gtk/win_place.h (nonexistent) +++ trunk/src_plugins/hid_gtk/win_place.h (revision 2372) @@ -0,0 +1,21 @@ +#ifndef GHID_WIN_PLACE +#define GHID_WIN_PLACE +#include "gui.h" + +typedef enum { + WPLC_TOP, + WPLC_LOG, + WPLC_DRC, + WPLC_LIBRARY, + WPLC_NETLIST, + WPLC_KEYREF, + WPLC_PINOUT, + WPLC_max +} wplc_win_t; + +/* Place the window if it's enabled and there are coords in the config. */ +void wplc_place(wplc_win_t id, GtkWidget *win); + +/* query window current window sizes and update wgeo cache */ +void wplc_config_event(GtkWidget *win, long *cx, long *cy, long *cw, long *ch); +#endif