[SOLVED] How do you detect when the active app or window changes with GTK+ in C?

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
User avatar
otacon14112
Level 2
Level 2
Posts: 64
Joined: Sun Apr 21, 2013 11:43 pm

[SOLVED] How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 » Sun Nov 26, 2017 1:11 am

I'm studying GTK+, and I'm trying to find out a way for my program to know every time a window or application becomes the new active one, or gains focus. For example, I'm trying to learn how to write a global menu bar. I want it to behave similarly to Mac OS, so for example, when you click on another window, if it's a different application, you're presented with different menu options. But first I need to figure out a way to let my program get notified every time a window becomes the active window.

I read that in Xlib, you can set a flag for substructure redirection but that totally intercepts a signal, and the window that wants to be remapped won't be, because whatever program requested the notification will get the command from the window manager instead. But I'm wanting to use GTK+. I don't want to prevent an app or window from being remapped, raised, or gain the focus; I just want to know when it happens, and the window ID atom of the window, so that I can find out more information about that window.

Is it possible in GTK+?
Last edited by otacon14112 on Tue Dec 12, 2017 2:31 am, edited 2 times in total.
Otacon: You remember pre-ripped jeans? Manufacturers thought that just because people loved old, broken-in jeans, they would want to buy new jeans that looked old. So they purposefully...
Solid Snake: What do jeans have to do with nature and order?

JosephM
Level 6
Level 6
Posts: 1036
Joined: Sun May 26, 2013 6:25 pm

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by JosephM » Sun Nov 26, 2017 6:03 am

What your talking about is normally the province of the window manager. What you might want to do is look at something like libwnck. It's what things like mate-panel use to get similar information for it's window list. It works with gtk and might give you a place to get started.

https://developer.gnome.org/libwnck/stable/
When I give opinions, they are my own. Not necessarily those of any other Linux Mint developer or the Linux Mint project as a whole.

User avatar
otacon14112
Level 2
Level 2
Posts: 64
Joined: Sun Apr 21, 2013 11:43 pm

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 » Mon Nov 27, 2017 5:56 pm

Thanks
Otacon: You remember pre-ripped jeans? Manufacturers thought that just because people loved old, broken-in jeans, they would want to buy new jeans that looked old. So they purposefully...
Solid Snake: What do jeans have to do with nature and order?

User avatar
otacon14112
Level 2
Level 2
Posts: 64
Joined: Sun Apr 21, 2013 11:43 pm

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 » Sun Dec 10, 2017 4:23 pm

Unfortunately, libwnck is unstable. It's strange, because in the uri it says stable, but when I click on the relevant widgets on the link you sent me, they're all unstable. I went ahead anyway, and tried to make some sample programs to test it out, and it wouldn't even compile, giving me an error and refusing to compile it because it was unstable, and even went so far to suggest NOT using it.
Otacon: You remember pre-ripped jeans? Manufacturers thought that just because people loved old, broken-in jeans, they would want to buy new jeans that looked old. So they purposefully...
Solid Snake: What do jeans have to do with nature and order?

User avatar
otacon14112
Level 2
Level 2
Posts: 64
Joined: Sun Apr 21, 2013 11:43 pm

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 » Tue Dec 12, 2017 2:29 am

JosephM wrote:What your talking about is normally the province of the window manager. What you might want to do is look at something like libwnck. It's what things like mate-panel use to get similar information for it's window list. It works with gtk and might give you a place to get started.

https://developer.gnome.org/libwnck/stable/
I just found out that a preprocessor definition is needed in order for it to compile, so now it appears I can move forward. I want to thank you again.
Otacon: You remember pre-ripped jeans? Manufacturers thought that just because people loved old, broken-in jeans, they would want to buy new jeans that looked old. So they purposefully...
Solid Snake: What do jeans have to do with nature and order?

Post Reply

Return to “Other topics”