|
List Info
Thread: wnck_screen_get_windows() returns empty window list
|
|
| wnck_screen_get_windows() returns empty
window list |

|
2006-06-26 00:54:39 |
(I hereby join the growing list of people asking libwnck
questions on
the Metacity development list, since it's really not clear
where libwnck
questions belong. Please accept my apologies if this is not
the
appropriate forum.)
I'm trying to get a list of windows on the default screen.
However, the
obvious combination of wnck_screen_get_default() plus
wnck_screen_get_windows() returns a NULL GList:
------------------------------------------------------------
------------
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
WnckScreen * const screen =
wnck_screen_get_default();
GList * const windows =
wnck_screen_get_windows(screen);
printf("window list: %p\n", windows);
g_list_free(windows);
return 0;
}
==>
window list: (nil)
------------------------------------------------------------
------------
I've tried the Python analogue and it behaves analogously,
yielding an
empty list:
------------------------------------------------------------
------------
import wnck
windows = wnck.screen_get_default().get_windows()
print 'window list:', windows
==>
window list: []
------------------------------------------------------------
------------
Am I missing something *really* obvious here?
_______________________________________________
metacity-devel-list mailing list
metacity-devel-list gnome.org
http://mail.gnome.org/mailman/listinfo/metacity-devel-
list
|
|
| wnck_screen_get_windows() returns empty
window list |

|
2006-06-26 18:03:18 |
On 6/25/06, Ben Liblit <liblit cs.wisc.edu> wrote:
> (I hereby join the growing list of people asking
libwnck questions on
> the Metacity development list, since it's really not
clear where libwnck
> questions belong. Please accept my apologies if this
is not the
> appropriate forum.)
>
> I'm trying to get a list of windows on the default
screen. However, the
> obvious combination of wnck_screen_get_default() plus
> wnck_screen_get_windows() returns a NULL GList:
(Letting this go to the list instead of answering outside,
as it seems
a lot more people are asking this recently, and I've been
meaning to
ask Havoc about it...)
It's not anything obvious you're missing, as evidenced by
the fact
that it seems to trip up everyone who ever tries to use
libwnck. If
we ever get around to writing a FAQ or some documentation,
this
particular question would need to be covered first. libwnck
is
essentially unusable until the idle handler has run, as it
merely
queues an update when the screen is first constructed (with
e.g. the
wnck_screen_get_default() call). Any calls to get the
window list
will merely return the "current" list of windows
-- this is a list
that will always lag the correct list since libwnck has to
wait for
notification from the Xserver of the various changes; in
particular,
this is a problem when first starting as the
"lagging" means that the
window list is empty until the idle handler runs for the
first time.
We could get rid of this stumbling block, I believe, by
calling
wnck_screen_force_update() within wnck_screen_construct().
But, there
might have been a reason to not do that, so I need to ask
Havoc if
such a change would be a good idea or not.
_______________________________________________
metacity-devel-list mailing list
metacity-devel-list gnome.org
http://mail.gnome.org/mailman/listinfo/metacity-devel-
list
|
|
| wnck_screen_get_windows() returns empty
window list |

|
2006-06-26 18:03:46 |
Ben Liblit wrote:
> Am I missing something *really* obvious here?
Perhaps not obvious, but maybe pretty simple; libwnck is all
asynchronous. There's some kind of "force
update" function on WnckScreen
iirc, or if you're going to watch for change notifications
anyway, all
the windows should appear once you return to the main loop.
There's a reason libwnck was always marked as "not
public API" - it
should be a lot better designed API-wise if it were intended
for wide
usage...
Havoc
_______________________________________________
metacity-devel-list mailing list
metacity-devel-list gnome.org
http://mail.gnome.org/mailman/listinfo/metacity-devel-
list
|
|
| wnck_screen_get_windows() returns empty
window list |

|
2006-06-26 18:28:03 |
Elijah Newren wrote:
>
> We could get rid of this stumbling block, I believe, by
calling
> wnck_screen_force_update() within
wnck_screen_construct(). But, there
> might have been a reason to not do that, so I need to
ask Havoc if
> such a change would be a good idea or not.
My guess with no research is that I wanted to avoid having
to "get the
current state" after constructing the screen, i.e.
screen = wnck_screen_new();
signal_connect(screen, "window-added",
handler);
then right now it can rely on the handler being called for
all windows,
if you did the update in the constructor then you have to
add code here
to manually call the handler for all existing windows.
I'm just guessing... you might want to look at what the
panel applets
really do.
The overall idea here is that async is almost always the
correct way to
write an X app, unless it's a run-once-and-exit command
line utility,
and so metacity and libwnck/wnck-using-applets are all
completely async.
If you're writing all the async stuff anyhow there's no
point putting a
possibly-inefficient or possible-reentrancy-issue-causing
forced update
in the constructor. It just encourages bugs where you init
one way and
then handle changes another way, or race conditions.
The other rule for async sanity of course is "don't
write through the
cache" i.e. if we have a local copy of the data and
ask the server to
change it, don't change the local copy, just let the change
notification
from the server update it. Elijah you'll be well familiar
with this from
metacity but also gconf etc. Anyway I imagine people will
find this
confusing as well...
libwnck as a whole is an atrociously
not-designed-for-public-use API
though, sort of very "GTK 1.0" ... I'd
certainly suggest that anyone
using libwnck be prepared to dive into the libwnck source
code and
diagnose oddities.
Havoc
_______________________________________________
metacity-devel-list mailing list
metacity-devel-list gnome.org
http://mail.gnome.org/mailman/listinfo/metacity-devel-
list
|
|
| wnck_screen_get_windows() returns empty
window list |

|
2006-06-26 19:22:13 |
Thanks, Elijah and Havoc!
I'll document the corrected version of the Python code here
for the
benefit of anyone Googling around for this in the future:
------------------------------------------------------------
---
import wnck
screen = wnck.screen_get_default()
screen.force_update()
windows = screen.get_windows()
print 'window list:', windows
==>
window list: [<wnck.Window object (WnckWindow at
0xb7ba5644, ...]
------------------------------------------------------------
---
I agree with Havoc's point about X apps being mostly
asynchronous. In
this particular case, though, I really am writing a
non-interactive
"fire once then exit" sort of script, so
wnck_screen_force_update() was
exactly what I needed. Thank you!
_______________________________________________
metacity-devel-list mailing list
metacity-devel-list gnome.org
http://mail.gnome.org/mailman/listinfo/metacity-devel-
list
|
|
[1-5]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|