如何查找桌面窗口

软件和网站开发以及相关技术探讨
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

如何查找桌面窗口

#1

帖子 eexpress » 2011-11-07 19:40

谁会找的。任何语言都可以。

代码: 全选

● xwininfo -tree -root|grep -C 6 desktop
           0x2c005b5 (has no name): ()  950x2+9+0  +902+355
           0x2c005b4 (has no name): ()  23x44+0+0  +893+355
     0x1600111 (has no name): ()  1920x1080+0+0  +0+0
        1 child:
        0x1600112 (has no name): ()  1920x1080+0+0  +0+0
           1 child:
           0x1c00004 "桌面": ("desktop_window" "Nautilus")  1920x1080+0+0  +0+0
              2 children:
              0x1c00072 (has no name): ()  1920x1080+0+0  +0+0
              0x1c00005 (has no name): ()  1x1+-1+-1  +-1+-1
     0x1200003 "main.py": ("main.py" "Main.py")  24x14+1876+1026  +1876+1026
        1 child:
        0x1200004 (has no name): ()  1x1+-1+-1  +1875+1025

代码: 全选

● dog drawonroot.pl 

sub wininfo{
my $w=shift;
my ($x, $y, $width, $height, $depth) = $w->get_geometry;
printf "%10x:\t${width}x$height+$x+$y\@$depth\ttype:%s\n", $w->get_xid, $w->get_type_hint;
}
Gtk2->init;
$window=Gtk2::Gdk->get_default_root_window;
($drawable,$x_offset,$y_offset)=$window->get_internal_paint_info;
wininfo($window);
@wlist = $window->get_children;
foreach(@wlist){ wininfo($_); }
wininfo($_);
exit;
只得到

代码: 全选

● drawonroot.pl 
       15d:	1920x1080+0+0@24	type:normal
   3c00001:	10x10+10+10@24	type:normal
    a0000a:	10x10+0+0@24	type:normal
而3c00001 a0000a 在 xwininfo -tree -root里面根本没有。
就算直接从xwininfo的结果得到 0x1c00004,怎么指定此窗口?
$_=Gtk2::Gdk::Window->lookup(0x1c00004); 可不行。
● 鸣学
头像
luojie-dune
帖子: 22033
注册时间: 2007-07-30 18:28
系统: Linux
来自: 空气中

Re: 如何查找桌面窗口

#2

帖子 luojie-dune » 2011-11-10 10:06

窗口管理器不同,就不同吧
『这个世界都是我的 ,我爱你们』

ENTP ⥂ INTP ⥄ INFP ⇦ INTJ

在此发布的文章使用 Creative Commons Attribution-ShareAlike 4.0 协议
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 如何查找桌面窗口

#3

帖子 eexpress » 2011-11-15 10:49

代码: 全选

● cat drawonroot.pl 
#!/usr/bin/perl

use Gtk2 "-init";
use Cairo;
use utf8;
use X11::Protocol;
#libx11-protocol-perl

my $x = X11::Protocol->new();
my $desktop;

my ($root,undef,@kids)=$x->QueryTree($x->{'root'});
printf "%10x:\tRoot\n", $root;
foreach (@kids){
my $gdkw = Gtk2::Gdk::Window->foreign_new($_);
printf ("%10x:\tDesktop\n",$gdkw->get_xid),$desktop=$gdkw,last if $gdkw->get_type_hint eq 'desktop';
}
#$desktop=Gtk2::Gdk->get_default_root_window if ! $desktop;
$desktop=Gtk2::Gdk::Window->foreign_new($root) if ! $desktop;
#● gconftool-2 -s /apps/nautilus/preferences/show_desktop false -t bool

$desktop=Gtk2::Gdk::Window->foreign_new(0x380afbd);
my ($x, $y, $width, $height, $depth) = $desktop->get_geometry;
printf "%10x:\tFind\t$width x $height + $x + $y \@ $depth\n", $desktop->get_xid;
my ($drawable,$x_offset,$y_offset)=$desktop->get_internal_paint_info;

Gtk2->init;
#$desktop=Gtk2::Gdk::Window->foreign_new(0x1e0592f);
#$desktop=Gtk2::Gdk::Window->foreign_new(0x1e0592f);
#$desktop=Gtk2::Gdk::Window->foreign_new(0x180002b);
#$pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ('/home/eexp/图片/irc.png');
#my $pixbuf=Gtk2::Gdk::Pixbuf->new('rgb',TRUE,8,$width,$height);
#$pixbuf1=$pixbuf->scale_simple ($width, $height, "GDK_INTERP_BILINEAR");
#my $pixmap = $pixbuf1->render_pixmap_and_mask (1);
#$cr = Gtk2::Gdk::Cairo::Context->create ($pixmap);

#$pixmap = Gtk2::Gdk::Pixmap->new($drawable, $width, $height, $depth);

#$pixmap = Gtk2::Gdk::Pixmap->foreign_new($desktop->get_xid);
#my $gc = Gtk2::Gdk::GC->new ($desktop, undef);
#$pixbuf1->render_to_drawable($drawable,
#                             $gc,
#                             0,0,0,0,$width,$height,'normal',0,0);
#$pixbuf1->save('/home/eexp/w.jpg','jpeg',quality=>'100');
$cr = Gtk2::Gdk::Cairo::Context->create ($drawable);
cairo();
#$desktop->set_back_pixmap($pixmap,0);
#$desktop->clear();
Gtk2->main_iteration;
#Gtk2->main_iteration while Gtk2->events_pending;
#Gtk2->main;

sub cairo {
#$cr->select_font_face("Amerika",'normal','bold');
$cr->select_font_face("Amerika Sans",'normal','bold');
$cr->set_font_size(40);
$cr->set_source_rgba(10,0,70,0.5);
$cr->move_to(40,40);
$cr->show_text("Cairo on Desktop");
print ".";
}

窗口终于找到了。只是突然不能画了。其他窗口都正常。
● 鸣学
回复