summaryrefslogtreecommitdiff
path: root/plugins/gtkui
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-03-10 12:05:31 +0100
committerGravatar waker <wakeroid@gmail.com>2011-03-10 12:05:31 +0100
commit6a06471b33a6825e0311d27520b66e32271a630c (patch)
tree4960cc9fcabe97103275c4443864cdb2b2a069e1 /plugins/gtkui
parent4593c75d53f43af914bbfb313dbe394abc0b7abf (diff)
added reusable window geometry save/restore functions
Diffstat (limited to 'plugins/gtkui')
-rw-r--r--plugins/gtkui/Makefile.am3
-rw-r--r--plugins/gtkui/callbacks.c39
-rw-r--r--plugins/gtkui/gtkui.c23
-rw-r--r--plugins/gtkui/search.c64
-rw-r--r--plugins/gtkui/search.h3
-rw-r--r--plugins/gtkui/wingeom.c99
-rw-r--r--plugins/gtkui/wingeom.h31
7 files changed, 143 insertions, 119 deletions
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am
index a2f9ae30..ef0e06e0 100644
--- a/plugins/gtkui/Makefile.am
+++ b/plugins/gtkui/Makefile.am
@@ -34,7 +34,8 @@ GTKUI_SOURCES = gtkui.c gtkui.h\
eq.c eq.h\
actions.c actions.h\
dspconfig.c dspconfig.h\
- tagwritersettings.c tagwritersettings.h
+ tagwritersettings.c tagwritersettings.h\
+ wingeom.c wingeom.h
EXTRA_DIST = $(gtkui_VALASOURCES) deadbeef.glade
diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c
index bfe87d63..c1458ee3 100644
--- a/plugins/gtkui/callbacks.c
+++ b/plugins/gtkui/callbacks.c
@@ -43,6 +43,7 @@
#include "parser.h"
#include "drawing.h"
#include "eq.h"
+#include "wingeom.h"
//#define trace(...) { fprintf (stderr, __VA_ARGS__); }
#define trace(fmt,...)
@@ -634,21 +635,7 @@ on_mainwin_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
-#if GTK_CHECK_VERSION(2,2,0)
- GdkWindowState window_state = gdk_window_get_state (GDK_WINDOW (widget->window));
-#else
- GdkWindowState window_state = gdk_window_get_state (G_OBJECT (widget));
-#endif
- if (!(window_state & GDK_WINDOW_STATE_MAXIMIZED) && gtk_widget_get_visible (widget)) {
- int x, y;
- int w, h;
- gtk_window_get_position (GTK_WINDOW (widget), &x, &y);
- gtk_window_get_size (GTK_WINDOW (widget), &w, &h);
- deadbeef->conf_set_int ("mainwin.geometry.x", x);
- deadbeef->conf_set_int ("mainwin.geometry.y", y);
- deadbeef->conf_set_int ("mainwin.geometry.w", w);
- deadbeef->conf_set_int ("mainwin.geometry.h", h);
- }
+ wingeom_save (widget, "mainwin");
return FALSE;
}
@@ -666,7 +653,6 @@ on_find_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
search_start ();
- search_restore_attrs ();
}
void
@@ -814,26 +800,7 @@ on_mainwin_window_state_event (GtkWidget *widget,
GdkEventWindowState *event,
gpointer user_data)
{
- // based on pidgin maximization handler
-#if GTK_CHECK_VERSION(2,2,0)
- if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
- if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
- deadbeef->conf_set_int ("mainwin.geometry.maximized", 1);
- }
- else {
- deadbeef->conf_set_int ("mainwin.geometry.maximized", 0);
- }
- }
-#else
- GdkWindowState new_window_state = gdk_window_get_state(G_OBJECT(widget));
-
- if (new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
- deadbeef->conf_set_int ("mainwin.geometry.maximized", 1);
- }
- else {
- deadbeef->conf_set_int ("mainwin.geometry.maximized", 0);
- }
-#endif
+ wingeom_save_max (event, widget, "mainwin");
return FALSE;
}
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index b25317d7..22f94aff 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -46,6 +46,7 @@
#include "actions.h"
#include "pluginconf.h"
#include "gtkui_api.h"
+#include "wingeom.h"
#define trace(...) { fprintf(stderr, __VA_ARGS__); }
//#define trace(fmt,...)
@@ -276,15 +277,7 @@ mainwin_toggle_visible (void) {
gtk_widget_hide (mainwin);
}
else {
- int x = deadbeef->conf_get_int ("mainwin.geometry.x", 40);
- int y = deadbeef->conf_get_int ("mainwin.geometry.y", 40);
- int w = deadbeef->conf_get_int ("mainwin.geometry.w", 500);
- int h = deadbeef->conf_get_int ("mainwin.geometry.h", 300);
- gtk_window_move (GTK_WINDOW (mainwin), x, y);
- gtk_window_resize (GTK_WINDOW (mainwin), w, h);
- if (deadbeef->conf_get_int ("mainwin.geometry.maximized", 0)) {
- gtk_window_maximize (GTK_WINDOW (mainwin));
- }
+ wingeom_restore (mainwin, "mainwin", 40, 40, 500, 300, 0);
if (iconified) {
gtk_window_deiconify (GTK_WINDOW(mainwin));
}
@@ -967,17 +960,7 @@ gtkui_thread (void *ctx) {
gtk_window_set_icon_name (GTK_WINDOW (mainwin), "deadbeef");
#endif
- {
- int x = deadbeef->conf_get_int ("mainwin.geometry.x", 40);
- int y = deadbeef->conf_get_int ("mainwin.geometry.y", 40);
- int w = deadbeef->conf_get_int ("mainwin.geometry.w", 500);
- int h = deadbeef->conf_get_int ("mainwin.geometry.h", 300);
- gtk_window_move (GTK_WINDOW (mainwin), x, y);
- gtk_window_resize (GTK_WINDOW (mainwin), w, h);
- if (deadbeef->conf_get_int ("mainwin.geometry.maximized", 0)) {
- gtk_window_maximize (GTK_WINDOW (mainwin));
- }
- }
+ wingeom_restore (mainwin, "mainwin", 40, 40, 500, 300, 0);
gtkui_on_configchanged (NULL, 0);
gtkui_init_theme_colors ();
diff --git a/plugins/gtkui/search.c b/plugins/gtkui/search.c
index e6076722..d14c5a46 100644
--- a/plugins/gtkui/search.c
+++ b/plugins/gtkui/search.c
@@ -38,6 +38,8 @@
#include "gtkui.h"
+#include "wingeom.h"
+
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
@@ -49,27 +51,8 @@ extern GtkWidget *searchwin;
extern GtkWidget *mainwin;
void
-search_restore_attrs (void) {
- int x = deadbeef->conf_get_int ("searchwin.geometry.x", -1);
- int y = deadbeef->conf_get_int ("searchwin.geometry.y", -1);
- int w = deadbeef->conf_get_int ("searchwin.geometry.w", 450);
- int h = deadbeef->conf_get_int ("searchwin.geometry.h", 150);
- gtk_widget_show (searchwin);
- if (x != -1 && y != -1) {
- gtk_window_move (GTK_WINDOW (searchwin), x, y);
- gtk_window_resize (GTK_WINDOW (searchwin), w, h);
- if (deadbeef->conf_get_int ("searchwin.geometry.maximized", 0)) {
- gtk_window_maximize (GTK_WINDOW (searchwin));
- }
- gtk_window_present (GTK_WINDOW (searchwin));
- }
- else {
- gtk_window_resize (GTK_WINDOW (searchwin), w, h);
- }
-}
-
-void
search_start (void) {
+ wingeom_restore (searchwin, "searchwin", -1, -1, 450, 150, 0);
gtk_entry_set_text (GTK_ENTRY (lookup_widget (searchwin, "searchentry")), "");
gtk_widget_show (searchwin);
gtk_window_present (GTK_WINDOW (searchwin));
@@ -198,21 +181,7 @@ on_searchwin_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
-#if GTK_CHECK_VERSION(2,2,0)
- GdkWindowState window_state = gdk_window_get_state (GDK_WINDOW (widget->window));
-#else
- GdkWindowState window_state = gdk_window_get_state (G_OBJECT (widget));
-#endif
- if (!(window_state & GDK_WINDOW_STATE_MAXIMIZED) && gtk_widget_get_visible (widget)) {
- int x, y;
- int w, h;
- gtk_window_get_position (GTK_WINDOW (widget), &x, &y);
- gtk_window_get_size (GTK_WINDOW (widget), &w, &h);
- deadbeef->conf_set_int ("searchwin.geometry.x", x);
- deadbeef->conf_set_int ("searchwin.geometry.y", y);
- deadbeef->conf_set_int ("searchwin.geometry.w", w);
- deadbeef->conf_set_int ("searchwin.geometry.h", h);
- }
+ wingeom_save (widget, "searchwin");
return FALSE;
}
@@ -221,30 +190,7 @@ on_searchwin_window_state_event (GtkWidget *widget,
GdkEventWindowState *event,
gpointer user_data)
{
- if (!gtk_widget_get_visible (widget)) {
- return FALSE;
- }
- // based on pidgin maximization handler
-#if GTK_CHECK_VERSION(2,2,0)
- if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
- if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
- deadbeef->conf_set_int ("searchwin.geometry.maximized", 1);
- }
- else {
- deadbeef->conf_set_int ("searchwin.geometry.maximized", 0);
- }
- }
-#else
- GdkWindowState new_window_state = gdk_window_get_state(G_OBJECT(widget));
-
- if ()
- if (new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
- deadbeef->conf_set_int ("searchwin.geometry.maximized", 1);
- }
- else {
- deadbeef->conf_set_int ("searchwin.geometry.maximized", 0);
- }
-#endif
+ wingeom_save_max (event, widget, "searchwin");
return FALSE;
}
diff --git a/plugins/gtkui/search.h b/plugins/gtkui/search.h
index d1c28d92..98216d5c 100644
--- a/plugins/gtkui/search.h
+++ b/plugins/gtkui/search.h
@@ -30,9 +30,6 @@ search_start (void);
void
search_refresh (void);
-void
-search_restore_attrs (void);
-
int
search_get_idx (DdbListviewIter it);
diff --git a/plugins/gtkui/wingeom.c b/plugins/gtkui/wingeom.c
new file mode 100644
index 00000000..d47743c3
--- /dev/null
+++ b/plugins/gtkui/wingeom.c
@@ -0,0 +1,99 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2011 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <gtk/gtk.h>
+#include "wingeom.h"
+#include "../../deadbeef.h"
+#include "gtkui.h"
+
+void
+wingeom_save (GtkWidget *widget, const char *name) {
+#if GTK_CHECK_VERSION(2,2,0)
+ GdkWindowState window_state = gdk_window_get_state (GDK_WINDOW (widget->window));
+#else
+ GdkWindowState window_state = gdk_window_get_state (G_OBJECT (widget));
+#endif
+ if (!(window_state & GDK_WINDOW_STATE_MAXIMIZED) && gtk_widget_get_visible (widget)) {
+ int x, y;
+ int w, h;
+ char key[100];
+ gtk_window_get_position (GTK_WINDOW (widget), &x, &y);
+ gtk_window_get_size (GTK_WINDOW (widget), &w, &h);
+ snprintf (key, sizeof (key), "%s.geometry.x", name);
+ deadbeef->conf_set_int (key, x);
+ snprintf (key, sizeof (key), "%s.geometry.y", name);
+ deadbeef->conf_set_int (key, y);
+ snprintf (key, sizeof (key), "%s.geometry.w", name);
+ deadbeef->conf_set_int (key, w);
+ snprintf (key, sizeof (key), "%s.geometry.h", name);
+ deadbeef->conf_set_int (key, h);
+ }
+}
+
+void
+wingeom_save_max (GdkEventWindowState *event, GtkWidget *widget, const char *name) {
+ if (!gtk_widget_get_visible (widget)) {
+ return;
+ }
+ char key[100];
+ snprintf (key, sizeof (key), "%s.geometry.maximized", name);
+ // based on pidgin maximization handler
+#if GTK_CHECK_VERSION(2,2,0)
+ if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
+ if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
+ deadbeef->conf_set_int (key, 1);
+ }
+ else {
+ deadbeef->conf_set_int (key, 0);
+ }
+ }
+#else
+ GdkWindowState new_window_state = gdk_window_get_state(G_OBJECT(widget));
+
+ if (new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
+ deadbeef->conf_set_int (key, 1);
+ }
+ else {
+ deadbeef->conf_set_int (key, 0);
+ }
+#endif
+}
+
+void
+wingeom_restore (GtkWidget *win, const char *name, int dx, int dy, int dw, int dh, int dmax) {
+ char key[100];
+ snprintf (key, sizeof (key), "%s.geometry.x", name);
+ int x = deadbeef->conf_get_int (key, dx);
+ snprintf (key, sizeof (key), "%s.geometry.y", name);
+ int y = deadbeef->conf_get_int (key, dy);
+ snprintf (key, sizeof (key), "%s.geometry.w", name);
+ int w = deadbeef->conf_get_int (key, dw);
+ snprintf (key, sizeof (key), "%s.geometry.h", name);
+ int h = deadbeef->conf_get_int (key, dh);
+ if (x != -1 && y != -1) {
+ gtk_window_move (GTK_WINDOW (win), x, y);
+ }
+ gtk_window_resize (GTK_WINDOW (win), w, h);
+ snprintf (key, sizeof (key), "%s.geometry.maximized", name);
+ if (deadbeef->conf_get_int (key, dmax)) {
+ gtk_window_maximize (GTK_WINDOW (win));
+ }
+}
diff --git a/plugins/gtkui/wingeom.h b/plugins/gtkui/wingeom.h
new file mode 100644
index 00000000..9b468846
--- /dev/null
+++ b/plugins/gtkui/wingeom.h
@@ -0,0 +1,31 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2011 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifndef __WINGEOM_H
+#define __WINGEOM_H
+
+void
+wingeom_save (GtkWidget *widget, const char *name);
+
+void
+wingeom_save_max (GdkEventWindowState *event, GtkWidget *widget, const char *name);
+
+void
+wingeom_restore (GtkWidget *win, const char *name, int dx, int dy, int dw, int dh, int dmax);
+
+#endif