TK: Get the "usable" screensize"?

Hi,

how can I get the "usable" screensize in Ruby/TK?
I mean, the total screensize minus taskbar (on Windows).

I tried:

  require 'tk'
  root = TkRoot.new
  root.state('zoomed')
  Tk.update
  p TkWinfo.x(root)
  p TkWinfo.y(root)
  p TkWinfo.width(root)
  p TkWinfo.height(root)
  p TkWinfo.geometry(root)

but this gives me only
  total_screensize - (taskbar + window_decoration)

window_decoration is titlebar and borders of a window, maybe
even something else.

I found http://wiki.tcl.tk/11291 which points into the
same direction, but I cannot use it with success (it's TCL).

I'm using:
* Windows XP
* ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-mingw32]
* TCL/TK 8.5

Thank you,
Axel

Message-ID: <371e3d52-02e8-4d9a-8b2b-61aa440e3e65@v25g2000yqk.googlegroups.com>

how can I get the "usable" screensize in Ruby/TK?
I mean, the total screensize minus taskbar (on Windows).

I tried:

  require 'tk'
  root = TkRoot.new
  root.state('zoomed')
  Tk.update
  p TkWinfo.x(root)
  p TkWinfo.y(root)
  p TkWinfo.width(root)
  p TkWinfo.height(root)
  p TkWinfo.geometry(root)

but this gives me only
  total_screensize - (taskbar + window_decoration)

Hmmm.... Well, does this work?

···

From: Axel <a99.googlegroups.a99@dfgh.net>
Subject: TK: Get the "usable" screensize"?
Date: Tue, 2 Feb 2010 03:55:24 +0900
-------------------------------------------------------------------------
root = Tk.root
root.state(:zoomed)
Tk.update
root.geometry =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d)/
w = $1.to_i
h = $2.to_i
x = $3.to_i
y = $4.to_i
sw = root.winfo_screenwidth
sh = root.winfo_screenheight
rx = root.winfo_rootx
ry = root.winfo_rooty # maybe, taskbar height
usable_screenwidth = w + rx * 2 # maybe, x_border * 2
usable_screenheight = h + ry
taskbar_height = sh - usable_screenheight
-------------------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Message-ID: <371e3d52-02e8-4d9a-8b2b-61aa440e3e65@v25g2000yqk.googlegroups.com>

I found Total Window Geometry which points into the
same direction, but I cannot use it with success (it's TCL).

FYI, Ruby/Tk can use Tcl scripts.
For example,

···

From: Axel <a99.googlegroups.a99@dfgh.net>
Subject: TK: Get the "usable" screensize"?
Date: Tue, 2 Feb 2010 03:55:24 +0900
-------------------------------------------------------------------------
Tk.ip_eval <<EOS
   proc totalGeometry {{w .}} {
     set geom [wm geometry $w]
     regexp -- {([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)} $geom -> \
       width height decorationLeft decorationTop
       set contentsTop [winfo rooty $w]
       set contentsLeft [winfo rootx $w]
       # Measure left edge, and assume all edges except top are the
       # same thickness
       set decorationThickness [expr {$contentsLeft -
       $decorationLeft}]

       # Find titlebar and menubar thickness
       set menubarThickness [expr {$contentsTop - $decorationTop}]
       incr width [expr {2 * $decorationThickness}]
       incr height $decorationThickness
       incr height $menubarThickness
       return [list $width $height $decorationLeft $decorationTop]
    }
EOS

Tk.ip_eval <<EOS
  proc taskbar {{w .taskBarSize}} {
    catch {destroy $w}
    toplevel $w
    wm state $w zoomed
    update
    set val [expr {[winfo screenheight $w]-[winfo height $w]}]
    destroy $w
    return $val;
  }
EOS

Tk.tk_call("totalGeometry") #=> e.g. "220 72 0 0"
TkComm.simplelist(Tk.tk_call("totalGeometry")) #=> e.g. ["220", "72", "0", "0"]
TkComm.list(Tk.tk_call("totalGeometry")) #=> e.g. [220, 72, 0, 0]
TkComm.tk_tcl2ruby(Tk.tk_call("totalGeometry")) #=> e.g. [220, 72, 0, 0]
Tk.tk_call_to_simplelist("totalGeometry")) #=> e.g. ["220", "72", "0", "0"]
Tk.tk_call_to_list("totalGeometry")) #=> e.g. [220, 72, 0, 0]

top = TkToplevel.new
Tk.tk_call("totalGeometry", top) #=> e.g. "230 104 0 0"

Tk.tk_call("taskbar") #=> e.g. "47"
TkComm.number(Tk.tk_call("taskbar")) #=> e.g. 47
TkComm.tk_tcl2ruby(Tk.tk_call("taskbar")) #=> e.g. 47
-------------------------------------------------------------------------

Also, please see an example ext/tk/sample/tktree.rb and tktree.tcl on
Ruby's source tree.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Axel schrieb:

Hi,

how can I get the "usable" screensize in Ruby/TK?
I mean, the total screensize minus taskbar (on Windows).

I tried:

require 'tk'
root = TkRoot.new
root.state('zoomed')
Tk.update
p TkWinfo.x(root)
p TkWinfo.y(root)
p TkWinfo.width(root)
p TkWinfo.height(root)
p TkWinfo.geometry(root)

but this gives me only
total_screensize - (taskbar + window_decoration)

window_decoration is titlebar and borders of a window, maybe
even something else.

I found Total Window Geometry which points into the
same direction, but I cannot use it with success (it's TCL).

I'm using:
* Windows XP
* ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-mingw32]
* TCL/TK 8.5

Thank you,
Axel

MessageID:<4af30c88$0$83250$e4fe514c@news.xs4all.nl>
in comp.lang.tcl 11/06/2009

Tcl:
winfo screenheight .
winfo screenwidth .
wm maxsize .

the difference should be the raw window dimensions
minus titlebar, decoration, menubar (OSX), dock (OSX) and taskbar.

The mentioned thread was about X11
-roger

Hello Hidetoshi Nagai,

it works, thank you!

root = Tk.root
root.state(:zoomed)
Tk.update
root.geometry =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d)/
w = $1.to_i
h = $2.to_i
x = $3.to_i
y = $4.to_i
sw = root.winfo_screenwidth
sh = root.winfo_screenheight
rx = root.winfo_rootx
ry = root.winfo_rooty # maybe, taskbar height
usable_screenwidth = w + rx * 2 # maybe, x_border * 2
usable_screenheight = h + ry
taskbar_height = sh - usable_screenheight

I didn't know that TkRoot#geometry exists and that it gives another
result than TkRoot.winfo_geometry.

At present, when I look for documentation of Ruby/Tk-methods, I look
into the TCL/TK documentation, e.g, for #winfo_geometry I look into:

http://www.tcl.tk/man/tcl8.5/TkCmd/winfo.htm#M15

Where must I look up methods of TkRoot, for example TkRoot.geometry?
In TCL-WM?

wm manual page - Tk Built-In Commands ?

Axel

FYI, Ruby/Tk can use Tcl scripts.
For example,
...

Very interesting! Didn't know about this.

Axel

Message-ID: <b0725330-ff09-4e1c-bf37-6832b632211b@y12g2000yqh.googlegroups.com>

At present, when I look for documentation of Ruby/Tk-methods, I look
into the TCL/TK documentation, e.g, for #winfo_geometry I look into:

winfo manual page - Tk Built-In Commands

Yes. winfo_* methods and module methods of TkWinfo module are
the methods to call Tcl/Tk's winfo command.

Where must I look up methods of TkRoot, for example TkRoot.geometry?
In TCL-WM?

wm manual page - Tk Built-In Commands ?

Yes. Tk::Root and Tk::Toplevel class have the methods to call
Tcl/Tk's wm command. Those methods are defined at Tk::Wm module.

Ruby/Tk can treat some subcommands of Tcl's wm command as widget options.
For example, Ruby/Tk's

···

From: Axel <a99.googlegroups.a99@dfgh.net>
Subject: Re: TK: Get the "usable" screensize"?
Date: Wed, 3 Feb 2010 21:10:18 +0900
-----------------------------------------------------------------------
Tk::Toplevel.new(:geometry=>"300x150+200+100", :title=>"toplevel test")
# When ruby 1.9, the following notation is acceptable.
# Tk::Toplevel.new(geometry:"300x150+200+100", title:"toplevel test")
-----------------------------------------------------------------------
means Tcl/Tk's
-----------------------------------------------------------------------
toplevel .w0000
wm geometry .w0000 300x150+200+100
wm title .w0000 "toplevel test"
-----------------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Message-ID: <7db3d107-df68-47c9-9a0b-e4baf5b26a3f@z26g2000yqm.googlegroups.com>

> FYI, Ruby/Tk can use Tcl scripts.
> For example,
> ...

Very interesting! Didn't know about this.

And Ruby/Tk can load Tcl/Tk's dynamic libraries.
So, almost all of Tcl/Tk's extensions are available on Ruby/Tk.

···

From: Axel <a99.googlegroups.a99@dfgh.net>
Subject: Re: TK: Get the "usable" screensize"?
Date: Wed, 3 Feb 2010 21:20:05 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)