GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Inactive/ Active Window Signal

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
e-izmir-a
Familiar Face


Joined: 16 Jan 2008
Posts: 8
Location: Schaafheim - Frankfurt / Germany

PostPosted: Wed Jan 16, 2008 1:05 pm    Post subject: Inactive/ Active Window Signal Reply with quote

Hello Everybody,
I need your suggestion for my little problem. I've got a window widget and I am drawing many little things on it with cairo. Now I have to draw a shape when the window is active, and change the colour of the shape if not. I know how to fetch the current state of the window for checking the activity ( gtk_window_is_active () ), but there is no signal for it. For drawing on the window surface, I am using the "expose" signal, but this signal is not the best solution for checking the window state, because the expose signal will be only called if there is anything to redraw (for example by maximizing the window or so on).

My question is: Is there any signal, that will be called, if the window is active/inactive?

I have looked at the API of GTK, but I did not found any signal or a brief of information.

Thank you for your helps,
Ercan


Last edited by e-izmir-a on Wed Jan 16, 2008 8:10 pm; edited 1 time in total
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 465
Location: Portland, OR USA

PostPosted: Wed Jan 16, 2008 1:54 pm    Post subject: Reply with quote

Code: (C)
1
2
3
4

GtkWindow *my_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* ... */
GdkWindowState state = gdk_window_get_state (my_window->window);


That will give you one of the following...

GDK_WINDOW_STATE_WITHDRAWN
the window is not shown.

GDK_WINDOW_STATE_ICONIFIED
the window is minimized.

GDK_WINDOW_STATE_MAXIMIZED
the window is maximized.

GDK_WINDOW_STATE_STICKY
the window is sticky.

GDK_WINDOW_STATE_FULLSCREEN
the window is maximized without decorations.

GDK_WINDOW_STATE_ABOVE
the window is kept above other windows.

GDK_WINDOW_STATE_BELOW
the window is kept below other windows.
Back to top
e-izmir-a
Familiar Face


Joined: 16 Jan 2008
Posts: 8
Location: Schaafheim - Frankfurt / Germany

PostPosted: Wed Jan 16, 2008 2:06 pm    Post subject: Reply with quote

Yes, you are right, but I need a signal, that will be called if the window is active/inacative.

I have tried this code:

Code: (C)
1
2
3
4
        g_signal_connect (G_OBJECT ( window),
                          "window_state_event",
                          G_CALLBACK ( state_event ),
                          NULL);

Code: (C)
1
2
3
4
5
6
7
8
9
10

void state_event (GtkWidget* widget,
                                    GdkEventWindowState *event,
                                    gpointer userdata)
{
    if( event->changed_mask & GDK_WINDOW_STATE_ABOVE  ) {
        g_print("State: Active\n\n");
    }   

}


But it cannot reach the code, where prints the string "State: Active". That means this code will not work :(

Any other suggestions?

Thanks,
Ercan
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 465
Location: Portland, OR USA

PostPosted: Wed Jan 16, 2008 2:13 pm    Post subject: Reply with quote

I believe your GDK_WINDOW_STATE_ABOVE flag is only tripped when the window is set to stay above all windows or that feature is turned off. This would not be tripped when the window is simply brought to the top of another window through you selecting it in your window manager.
Back to top
e-izmir-a
Familiar Face


Joined: 16 Jan 2008
Posts: 8
Location: Schaafheim - Frankfurt / Germany

PostPosted: Wed Jan 16, 2008 2:19 pm    Post subject: Reply with quote

Micah Carrick wrote:
I believe your GDK_WINDOW_STATE_ABOVE flag is only tripped when the window is set to stay above all windows or that feature is turned off. This would not be tripped when the window is simply brought to the top of another window through you selecting it in your window manager.


It sounds right. But how can I solve this problem? I have no ideas to get the window state while the window is active/inactive...

Isn't there any signal, who done exactly this job?

Thanks,
Ercan
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 465
Location: Portland, OR USA

PostPosted: Wed Jan 16, 2008 2:27 pm    Post subject: Reply with quote

I can't recall off the top of my head... I think the "expose-event" maybe what you're looking for? Take a look at the source code for the GdkDrawingArea example from Andrew's book: Foundations of GTK+ Development at http://gtkbook.com/
Back to top
e-izmir-a
Familiar Face


Joined: 16 Jan 2008
Posts: 8
Location: Schaafheim - Frankfurt / Germany

PostPosted: Wed Jan 16, 2008 2:31 pm    Post subject: Reply with quote

Micah Carrick wrote:
I can't recall off the top of my head... I think the "expose-event" maybe what you're looking for? Take a look at the source code for the GdkDrawingArea example from Andrew's book: Foundations of GTK+ Development at http://gtkbook.com/


"expose-event" will not work, because this signal will be only called if there is anything to redraw by minimizing or changing the window size (and so on)...

Okay, I'll looking to the source codes, maybe I'll find anything that help me to solve this little problem.

Can you tell me a solution, if you find anything?

Thanks,
Ercan
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP