Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[ALLY] getting the screen-size Re:

From: holger:rebol at: 15-Aug-2000 6:35

On Tue, Aug 15, 2000 at 04:18:38PM +1000, [allenk--powerup--com--au] wrote:
> Here is a little function that can return the screen size. This one will > work on all OS's including BeOS, and those Linux systems that can't initiate > the screen-face until after a face is shown. On some platforms, screen-face > returns a size of 100x100 until after face is shown (because the gui libs > have to be loaded). > > Most of us want to the know the screen size before we show our main face, > (for window sizing or centering), and also want the script to run on all > platforms. Thanks to Bo for suggesting this idea. > > screen-size: does [ > if system/view/screen-face/size = 100x100 [view/new make face [1x1] > unview/all] > system/view/screen-face/size > ]
This is not really a good idea. First of all, the initial value is not likely to remain 100x100. This is NOT a magic number, and chances are it will become 640x480 or 800x600 in future versions, probably platform-dependent. Second, please consider that showing the first face can cause some overhead on some systems (connecting to an X server or, on the Amiga, possibly opening a file requester asking for a screen mode and size). Users may not want that to happen until the window is actually displayed, not to mention that briefly popping up a tiny window, with decorations and borders, seems ugly. On some window managers (e.g. twm with default settings) the window manager will prompt the user for the window position by showing a window outline, then once the user clicks the mouse button the window will be displayed, then it will disappear, and then the window manager will display another window outline for the real window requiring another mouse click -- very, very ugly. Third, on some systems that support different screens and screen sizes (in particular Amiga) View tries to create a screen large enough to accomodate the first window you open. This is necessary because a lot of View scripts are written to require 640x480 plus window borders, but without graphics boards most Amigas are limited to around 640x400, requiring special tricks (such as virtual screens with autoscroll) to show larger windows. If you open a tiny window first then you defeat this mechanism, and the screen size reported to you will be unnecessarily small (probably 640x400 or even 640x200). Finally, you really have no control over the size of borders, title bars etc., so it is impossible to properly size and center your window anyway, based on just the screen size. On some platforms (again, in particular AmigaOS and X11) the size of decorations can vary a LOT, and even be different for different windows on the same screen (e.g. some X window managers are by default configured to remove window borders for any programs that have the word "clock" in the program name). Bottom line: this is really a chicken-egg issue. (On some systems) View needs to know the initial window size in order to create a suitable screen, which assumes that the screen size follows the window size. Yet on other systems the screen size is fixed, so the window size has to follow the screen size. For the moment I don't see any solution that works on all platforms. I don't really like the idea of scripts getting fancy in the way they check the screen size, trying to outsmart the View OS module, because this is likely to limit cross-platform portability, and will restrict us at REBOL in providing future enhancements. Here is an idea how it COULD work in one of the next versions: - Centering a window (with a known window size) is something View should be able to do by itself. This seems like a good candidate for a language extension. - If your window needs to know (and I mean REALLY needs to know) the screen size for other purposes, e.g. if the window has a complex layout and some parts of it are resizable, then check system/view/screen-face/size. If it is 100x100 or less then assume 640x400 to be the available screen size (for compatibility with current versions of View). An idea we have been tossing around is for system/view/screen-face/size to become a function which, upon first access, asks the OS for "some" screen size and then stores the value, in much the same way the various "password"s in system/schemes work. "Asking the system" would be done in a non-destructive way, i.e. without opening a screen or popping up a requester. Of course this would mean that on some systems (like AmigaOS) that size is only a guess, probably derived from the size of the Workbench screen. The final size may be larger or smaller and would be stored in system/view/screen-face/size after the first window has opened, possibly after putting up a requester. On systems where the final size can be different from the guessed size it would be View's job to ensure that the first window can be displayed if a script used the guessed size to size the window. - This leaves the problem on how to calculate window borders. No solution to this yet, but the proper solution is likely to be similar (functions which ask the system). For now please be VERY conservative, i.e. if you have to dynamically size your window then assume that the borders and title bar are quite large. Jim, any comments ? -- Holger Kruse [holger--rebol--com]