+
+gboolean window_focus_in_clear_focus_widget(ui::Window widget, GdkEventKey *event, gpointer data)
+{
+ gtk_window_set_focus( widget, NULL );
+ return FALSE;
+}
+
+guint window_connect_focus_in_clear_focus_widget(ui::Window window)
+{
+ return window.connect( "focus_in_event", G_CALLBACK( window_focus_in_clear_focus_widget ), NULL );
+}
+
+void window_get_position(ui::Window window, WindowPosition &position)
+{
+ ASSERT_MESSAGE( window , "error saving window position" );
+
+ gtk_window_get_position( window, &position.x, &position.y );
+ gtk_window_get_size( window, &position.w, &position.h );
+}
+
+void window_set_position(ui::Window window, const WindowPosition &position)
+{
+ gtk_window_set_gravity( window, GDK_GRAVITY_STATIC );
+
+ GdkScreen* screen = gdk_screen_get_default();
+ if ( position.x < 0
+ || position.y < 0
+ || position.x > gdk_screen_get_width( screen )
+ || position.y > gdk_screen_get_height( screen ) ) {
+ gtk_window_set_position( window, GTK_WIN_POS_CENTER_ON_PARENT );
+ }
+ else
+ {
+ gtk_window_move( window, position.x, position.y );
+ }
+
+ gtk_window_set_default_size( window, position.w, position.h );
+}
+
+void WindowPosition_String::Import(WindowPosition &position, const char *value)
+{
+ if ( sscanf( value, "%d %d %d %d", &position.x, &position.y, &position.w, &position.h ) != 4 ) {
+ position = WindowPosition( c_default_window_pos ); // ensure sane default value for window position
+ }
+}
+
+void WindowPosition_String::Export(const WindowPosition &self, const Callback<void(const char *)> &returnz)
+{
+ char buffer[64];
+ sprintf( buffer, "%d %d %d %d", self.x, self.y, self.w, self.h );
+ returnz( buffer );
+}
+
+void WindowPositionTracker_String::Import(WindowPositionTracker &self, const char *value)
+{
+ WindowPosition position;
+ WindowPosition_String::Import( position, value );
+ self.setPosition( position );
+}
+
+void WindowPositionTracker_String::Export(const WindowPositionTracker &self, const Callback<void(const char *)> &returnz)
+{
+ WindowPosition_String::Export( self.getPosition(), returnz );
+}
+
+gboolean WindowPositionTracker::configure(ui::Widget widget, GdkEventConfigure *event, WindowPositionTracker *self)
+{
+ self->m_position = WindowPosition( event->x, event->y, event->width, event->height );
+ return FALSE;
+}
+
+void WindowPositionTracker::sync(ui::Window window)
+{
+ window_set_position( window, m_position );
+}
+
+void WindowPositionTracker::connect(ui::Window window)
+{
+ sync( window );
+ window.connect( "configure_event", G_CALLBACK( configure ), this );
+}
+
+const WindowPosition &WindowPositionTracker::getPosition() const
+{
+ return m_position;
+}
+
+void WindowPositionTracker::setPosition(const WindowPosition &position)
+{
+ m_position = position;
+}