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

From: Axel [email protected]
Subject: TK: Get the “usable” screensize"?
Date: Tue, 2 Feb 2010 03:55:24 +0900
Message-ID:
[email protected]

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?

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

From: Axel [email protected]
Subject: TK: Get the “usable” screensize"?
Date: Tue, 2 Feb 2010 03:55:24 +0900
Message-ID:
[email protected]

I found http://wiki.tcl.tk/11291 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,

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.

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

Very interesting! Didn’t know about this.

Axel

Hello Hidetoshi Nagai,

it works, thank you!

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?

http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M28 ?

Axel

Axel schrieb:

Tk.update
even something else.
Axel

MessageID:[email protected]
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

From: Axel [email protected]
Subject: Re: TK: Get the “usable” screensize"?
Date: Wed, 3 Feb 2010 21:10:18 +0900
Message-ID:
[email protected]

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

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?

http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M28 ?

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

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”)

From: Axel [email protected]
Subject: Re: TK: Get the “usable” screensize"?
Date: Wed, 3 Feb 2010 21:20:05 +0900
Message-ID:
[email protected]

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs