For Programmers: Free Programming Magazines  


Home > Archive > Tcl > August 2004 > Detecting screen resolution









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Detecting screen resolution
arenatr

2004-08-21, 4:03 pm

I'm looking to get the max size of the screen for the computer on
which some TCL is being executed. I want to find out if the user has
a screen resolution of 1024 X 768, 1600 X 1200, etc. I'm guessing
it's in an evironment variable, but I don't exactly know how to access
this. Any help you can provide would be greatly appreciated.
Gerald W. Lester

2004-08-21, 4:03 pm

arenatr wrote:
> I'm looking to get the max size of the screen for the computer on
> which some TCL is being executed. I want to find out if the user has
> a screen resolution of 1024 X 768, 1600 X 1200, etc. I'm guessing
> it's in an evironment variable, but I don't exactly know how to access
> this. Any help you can provide would be greatly appreciated.


Please read the man/help page on the winfo command, pay particular
attention to the subcommands beginning with the string "screen".

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is |
| Gerald.Lester@cox.net | the man who is alive." -- Cervantes |
+--------------------------------+---------------------------------------+
Victor Wagner

2004-08-21, 4:03 pm

arenatr <arenatr@comcast.net> wrote:
> I'm looking to get the max size of the screen for the computer on
> which some TCL is being executed. I want to find out if the user has
> a screen resolution of 1024 X 768, 1600 X 1200, etc. I'm guessing
> it's in an evironment variable, but I don't exactly know how to access
> this. Any help you can provide would be greatly appreciated.


No, it is not environment variable. There is options in winfo command,
which are, quite surprisingly, called screenwidth and screenheight.

Window argument is required, because under X window Tk application can
simulteneously open windows on several physical displays. So
winfo screenwidth .some.window
would return width of screen where window .some.window is displayed.

I typically do [winfo screenwidth .], because window '.' guaranteed to
exist.


--
BREAKFAST.COM Halted... Cereal Port Not Responding.
arenatr

2004-08-24, 11:06 pm

vitus@45.free.net (Victor Wagner) wrote in message news:<cg889q$l1r$1@wagner.wagner.home>...
> arenatr <arenatr@comcast.net> wrote:
>
> No, it is not environment variable. There is options in winfo command,
> which are, quite surprisingly, called screenwidth and screenheight.
>
> Window argument is required, because under X window Tk application can
> simulteneously open windows on several physical displays. So
> winfo screenwidth .some.window
> would return width of screen where window .some.window is displayed.
>
> I typically do [winfo screenwidth .], because window '.' guaranteed to
> exist.


Thank you in advance for your help.

I did actually consult with the manual pages for winfo before I put
this post up. Unfortunately, the:

[winfo screenwidth .] command seems to still respond with the width of
whatever window is currently loaded, which is not what I'm looking
for.

I'm looking for the actual dimenions of the display monitor - the
maximum settings (or current settings, if the screen is not set to
maximum) of the size of the screen. So, for example, a standard CRT
monitor these days would have 1024 X 768 resolution,. An older would
have 800 X 600. An XGA laptop would have 1600 X 1200, etc. This is
actually what I'm looking for.

As far as I can tell, this winfo command gives instead the the screen
of the most recently loaded window.

Thank you in advance for your help!
Donald Arseneau

2004-08-25, 5:05 am

arenatr@comcast.net (arenatr) writes:

> [winfo screenwidth .] command seems to still respond with the width of
> whatever window is currently loaded, which is not what I'm looking
> for.


What window manager on what system? It sounds broken ... Or you
tried [winfo width .] previously and forgot which you tested.


Donald Arseneau asnd@triumf.ca
Andreas Leitgeb

2004-08-25, 5:06 am

arenatr <arenatr@comcast.net> wrote:
> I'm looking for the actual dimenions of the display monitor - the
> maximum settings (or current settings, if the screen is not set to
> maximum) of the size of the screen. So, for example, a standard CRT
> monitor these days would have 1024 X 768 resolution,. An older would
> have 800 X 600. An XGA laptop would have 1600 X 1200, etc. This is
> actually what I'm looking for.


You surely won't get *this* piece of information out if winfo!

Afterall, what you ask for is (imho) rubbish, because standard
CRTs may just well give you 1600x1200 resolution, but then with
a refresh-rate of say 30Hz ;-)

You should really assume that the current resolution is what
the user is most comfortable with, and don't even think about
trying to persuade him into choosing anything higher...

If your application *really* cannot run at 800x600, you just
popup a notice that says so, and if the user's hardware permits
it, he will switch the resolution to something higher, (if he
finds your prog worth it). And if he prefers a 800x600 @ 72Hz
to 1024x768 @ 60Hz (quite an old monitor that would be) then
he wouldn't want to ruin his eyes, anyway.

That said, perhaps there are external tools, that you could make
use of. on unix-platforms, "xrandr" springs to mind, for windoze
I don't know (perhaps abusing registry...)

Andreas Leitgeb

2004-08-25, 5:06 am

Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> wrote:
> arenatr <arenatr@comcast.net> wrote:
>
> You surely won't get *this* piece of information out if winfo!
>

Damn, reading it again, now it doesn't look to me at all anymore,
as if you had wanted the hardware's maximum capabilities.

So, for dimensions of screen, [winfo screenwidth .]
and [winfo screenheght .] is all you get.

If you started wish at say 800x600 and then switched to 1024x768,
then (according to some other thread) wish doesn't reflect it,
so you'd get the the 800x600 throughout all the running wish.
You might accellerate resolving this issue by submitting a
working patch... otherwise hope that someone else comes up with
one.

Victor Wagner

2004-08-25, 9:01 am

Donald Arseneau <asnd@triumf.ca> wrote:

[color=darkred]
> What window manager on what system? It sounds broken ... Or you
> tried [winfo width .] previously and forgot which you tested.


Or he mixes notions of window and video mode.

--
Linux poses a real challenge for those with a taste for late-night
hacking (and/or conversations with God).
-- Matt Welsh
Donal K. Fellows

2004-08-25, 9:01 am

arenatr wrote:
> I'm looking for the actual dimenions of the display monitor - the
> maximum settings (or current settings, if the screen is not set to
> maximum) of the size of the screen. So, for example, a standard CRT
> monitor these days would have 1024 X 768 resolution,. An older would
> have 800 X 600. An XGA laptop would have 1600 X 1200, etc. This is
> actually what I'm looking for.


Ah. This is not information that Tk provides at all. On Windows, I
think it is possible to pull this sort of information out of the
Registry (using the registry package distributed with Tcl) but this is
non-trivial.

Donal.
lvirden@gmail.com

2004-08-27, 8:58 am


According to arenatr <arenatr@comcast.net>:
:[winfo screenwidth .] command seems to still respond with the width of
:whatever window is currently loaded, which is not what I'm looking
:for.
:
:I'm looking for the actual dimenions of the display monitor - the
:maximum settings (or current settings, if the screen is not set to
:maximum) of the size of the screen. So, for example, a standard CRT
:monitor these days would have 1024 X 768 resolution,. An older would
:have 800 X 600. An XGA laptop would have 1600 X 1200, etc. This is
:actually what I'm looking for.
:
:As far as I can tell, this winfo command gives instead the the screen
:of the most recently loaded window.


Could you show us some code demonstrating your problem?

For instance, on my machine:

$ xdpyinfo
name of display: :0.0
version number: 11.0
vendor string: Sun Microsystems, Inc.
vendor release number: 6410
maximum request size: 262140 bytes
motion buffer size: 256
bitmap unit, bit order, padding: 32, MSBFirst, 32
image byte order: MSBFirst
number of supported pixmap formats: 4
supported pixmap formats:
depth 1, bits_per_pixel 1, scanline_pad 32
depth 8, bits_per_pixel 8, scanline_pad 32
depth 16, bits_per_pixel 16, scanline_pad 32
depth 24, bits_per_pixel 32, scanline_pad 32
keycode range: minimum 8, maximum 254
focus: window 0x5c0000e, revert to PointerRoot
number of extensions: 30
AccessX
Adobe-DPS-Extension
DOUBLE-BUFFER
DPMS
DPSExtension
Extended-Visual-Information
FBPM
GLX
LBX
MIT-SCREEN-SAVER
MIT-SHM
MIT-SUNDRY-NONSTANDARD
Multi-Buffering
RECORD
SECURITY
SHAPE
SUN_ALLPLANES
SUN_DGA
SUN_OVL
SUN_SME
SYNC
SolarisIA
TOG-CUP
XC-APPGROUP
XC-MISC
XIE
XINERAMA
XInputDeviceEvents
XInputExtension
XTEST
default screen number: 0
number of screens: 1

screen #0:
dimensions: 2560x1024 pixels (722x289 millimeters)
resolution: 90x90 dots per inch
depths (2): 1, 24
root window id: 0x27
depth of root window: 24 planes
number of colormaps: minimum 1, maximum 1
default colormap: 0x21
default number of colormap cells: 256
preallocated pixels: black 0, white 16777215
options: backing-store YES, save-unders YES
largest cursor: unlimited
current input event mask: 0xfa203f
KeyPressMask KeyReleaseMask ButtonPressMask
ButtonReleaseMask EnterWindowMask LeaveWindowMask
ButtonMotionMask StructureNotifyMask SubstructureNotifyMask
SubstructureRedirectMask FocusChangeMask PropertyChangeMask
ColormapChangeMask
number of visuals: 1
default visual id: 0x22
visual:
visual id: 0x22
class: TrueColor
depth: 24 planes
available colormap entries: 256 per subfield
red, green, blue masks: 0xff0000, 0xff00, 0xff
significant bits in color specification: 8 bits

which is seems to me would have you wanting to see a value of 2560 x 1024
back from Tk.

And so I type this:

$ wish
% winfo screenwidth .
2560
winfo screenheight .
1024



--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvirden@gmail.com > <URL: http://www.purl.org/NET/lvirden/ >
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com