LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-20-2017, 04:51 PM   #1
Otacon 141.12
LQ Newbie
 
Registered: Oct 2017
Distribution: Debian, Linux Mint, Ubuntu, Finnix
Posts: 28

Rep: Reputation: Disabled
Does libwnck have a way to get a list of child windows in C?


libwnck can list top-level windows with functions like
Code:
GList * wnck_application_get_windows (WnckApplication *app)
GList * wnck_screen_get_windows_stacked (WnckScreen *screen)
which return GLists of WnckWindows. I can also use
Code:
WnckWindowType wnck_window_get_window_type (WnckWindow *window)
to get the WnckWindowType. These show that libwnck can get lists of windows, and find their type.

Now, there is a type of WnckWindow called WNCK_WINDOW_MENU. However, when I use the functions above, it sees top-level windows only. For example, when I run this function:
Code:
void check_windows_by_app (WnckApplication *app)
{
        GList *l, *windows = wnck_application_get_windows(app);

        for (l = windows; l != NULL; l = l->next) {
                gpointer        element_data = l->data;
                WnckWindowType  win_type;

                win_type = wnck_window_get_window_type(element_data);
                g_print ("\nWindow type: %u\n\b",win_type);
        }
}
It shows that the list only contains WnckWindows of types WNCK_WINDOW_NORMAL and WNCK_WINDOW_DESKTOP.

All the windows in the list, except the desktop had menus. They were application windows like Caja, Pluma, Banshee, etc. However, the menus were not shown to be included in the list, because it did not print out any WNCK_WINDOW_MENU type.

I verified this from https://developer.gnome.org/libwnck/...WnckWindowType and from telling it to print out each type individually, along with its decimal-equivalent number next to it. The results were:
Code:
WNCK_WINDOW_NORMAL: 0
WNCK_WINDOW_DESKTOP: 1
WNCK_WINDOW_DOCK: 2
WNCK_WINDOW_DIALOG: 3
WNCK_WINDOW_TOOLBAR: 4
WNCK_WINDOW_MENU: 5
WNCK_WINDOW_UTILITY: 6
WNCK_WINDOW_SPLASHSCREEN: 7
Now, to show that the list doesn't contain anything but normal and desktop, I'll paste the output from the function. The lines with text were printed from the function that called the top function:
Code:
Active window changed.
----------------------
Previously active window: wnck_window types (~/Desktop/VBox files) - Pluma
Previously active app: Pluma
New active window: Documents
New active app: Caja

Window type: 0

Window type: 0

Window type: 0

Window type: 0

Window type: 1

Active window changed.
----------------------
Previously active window: Documents
Previously active app: Caja
New active window: wnck_window types (~/Desktop/VBox files) - Pluma
New active app: Pluma

Window type: 0

Active window changed.
----------------------
Previously active window: wnck_window types (~/Desktop/VBox files) - Pluma
Previously active app: Pluma
New active window: x-caja-desktop
New active app: Caja

Window type: 0

Window type: 0

Window type: 0

Window type: 0

Window type: 1
You can see that when I make a Caja window the active window, it lists all the instances of it being open, including the desktop "1".

It only shows 2 types of WnckWindows. What good is the menu type if it's not detected by the functions? How can I make it find menu windows? And is there a way for libwnck to search trees to find windows? Thanks

Last edited by Otacon 141.12; 12-20-2017 at 05:05 PM.
 
Old 12-21-2017, 12:01 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I'm not sure that I understand your question, but since I had never heard of libwnck I decided to check it out.

I added one line to the first example on this page: https://developer.gnome.org/libwnck/...g-started.html
Code:
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>

int main (int    argc, char **argv) {
  WnckScreen *screen;
  WnckWindow *active_window;
  GList *window_l;
  gdk_init (&argc, &argv);
  screen = wnck_screen_get_default ();
  wnck_screen_force_update (screen);
  active_window = wnck_screen_get_active_window (screen);
  for (window_l = wnck_screen_get_windows (screen); window_l != NULL; window_l = window_l->next)
    {
      WnckWindow *window = WNCK_WINDOW (window_l->data);
      g_print ("%s%s\n", wnck_window_get_name (window), window == active_window ? " (active)" : "");
      g_print ("type - %d\n",  wnck_window_get_window_type(window) );   // added this line
    }
  return 0;
}
Then I started GIMP, opened a tearoff menu and a help dialog and ran the above program.
Output:
Code:
Desktop ? Plasma
type - 1
Desktop ? Plasma
type - 1
Plasma
type - 2
Does libwnck have a way to get a list of child windows in C? - Google Chrome
type - 0
GNU Image Manipulation Program
type - 0
wnck_src : mc ? Konsole (active)
type - 0
GIMP Message   
type - 3
Image Menu
type - 5
Note that it properly identifies the tearoff menu (Image Menu).
From your link:
Quote:
WNCK_WINDOW_MENU the window is a tearoff menu.
HTH

Last edited by norobro; 12-21-2017 at 12:03 PM.
 
2 members found this post helpful.
Old 12-21-2017, 05:31 PM   #3
Otacon 141.12
LQ Newbie
 
Registered: Oct 2017
Distribution: Debian, Linux Mint, Ubuntu, Finnix
Posts: 28

Original Poster
Rep: Reputation: Disabled
So then that confirms what I suspected, that menus can only be listed this way if they're tear-off capable. Thank you.

What I am trying to do is get a list of all the child windows of a top-level window. Buttons, menus, scrollbars, labels, text boxes, etc, are all windows. Even the title bar and the buttons in the title bar are windows, such as the minimize, restore, and close buttons.

I have several X books, and it's stated in them that a normal window is made up of many smaller ones. The way I think I understand it is that the widgets are also child windows of the top-level window, unless I'm mistaken. I'm trying to get a list of all the child windows including the widgets, so that I can embed a widget or window into a Gtk socket, but I need the XID of the widget or window that I want to embed, and I don't know of any other way to get it, other than to search through the entire tree of the active window.

Edit: I haven't found a way to find them with libwnck, so I'm going to try Xlib and XQueryTree. I just wondered if libwnck could do it.

Last edited by Otacon 141.12; 12-21-2017 at 05:44 PM.
 
Old 12-21-2017, 08:33 PM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You're welcome.

"xwininfo -int" will give you a window id and much more info, but it is an interactive program.

Years ago I wrote a Qt app that embeds a window in a tab of a QTabWidget, but it requires knowing the win id of the widow to embed.

Quote:
Originally Posted by Otacon 141.12 View Post
... What I am trying to do is get a list of all the child windows of a top-level window. Buttons, menus, scrollbars, labels, text boxes, etc, are all windows. ...
AFAIK that is not correct. The buttons, menus and other widgets are drawn by the application framework in a top level window, not by X. Try running "xwininfo -children" and clicking on a Caja window.
Attached Thumbnails
Click image for larger version

Name:	embed.jpg
Views:	32
Size:	84.3 KB
ID:	26580  

Last edited by norobro; 12-21-2017 at 08:59 PM. Reason: corrected grammar
 
  


Reply

Tags
menus, windows



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list all child pages of current parent page in drupal 7 ? findnerd2 Programming 0 06-13-2015 03:45 PM
how to get a list of child processes? Thinking Programming 2 01-19-2006 07:42 AM
Having trouble using libwnck in my program. rob_of_ownsboro Programming 1 05-03-2005 04:25 PM
Trying to patch libwnck and create .deb tsalem Linux - Newbie 3 04-02-2005 07:44 PM
Help locating and patching libwnck on Ubuntu Vetti Linux - Software 3 03-21-2005 12:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration