Simple question

49 views
Skip to first unread message

Kevin Ingwersen (Ingwie Phoenix)

unread,
Mar 26, 2015, 4:44:55 AM3/26/15
to fltkg...@googlegroups.com
Hey.

I am playing around with some of the functions like fl_ask(). I noticed that calling that function puts the window to the bottom left of my screen. How could I possibly center that alert instead? And in general, how do I center a window?

With center, i mean the very center of the entire screen.

Kind regards, Ingwie

Ian MacArthur

unread,
Mar 26, 2015, 5:58:24 AM3/26/15
to fltkg...@googlegroups.com
On Thu Mar 26 2015 08:43:17, Kevin Ingwersen (Ingwie Phoenix) wrote:
>
> Hey.
>
> I am playing around with some of the functions like fl_ask(). I noticed that calling that function puts the window to the bottom left of my screen. How could I possibly center that alert instead?

The fltk common dialogs (fl_ask et al) don’t have a mechanism to explicitly position them at a given x,y so if you need that ability, you have to create your own dialog boxes. Which isn’t that hard, but just a bit of a nuisance.

By default, the fltk common dialogs use a hotspot mechanism to position the dialogs, such that the dialog will try and position itself so that the default button is under (or at least very near to) the current mouse cursor position.

The hotspot can be enabled/disabled, but I;m pretty sure it is on by default.

However, not all WM will correctly respect he requested dialog position, and there’s not much we can do about that (try another WM?)... so the behaviour you are seeing is either because (a) that is where your mouse happened to be or (b) the WM is ignoring our window position requests.


> And in general, how do I center a window?

The usual way is to use the various Fl::screen_* methods to figure out who many display there are, and which one you want to display your dialog on.

The you use the Fl::screen_work_area() or Fl::screen_xywh() methods to determine the dimensions of the screen; then you just position your window like:

pos_x = screen_x + ((screen_width - window_width) / 2);

(and equivalently for the y pos) and that ought do the trick.
There’s not really a shorter way, as you first need to figure out if there’s more than one screen and if so which one you want to display on...





Greg Ercolano

unread,
Mar 26, 2015, 7:22:01 AM3/26/15
to fltkg...@googlegroups.com
On 03/26/15 02:58, Ian MacArthur wrote:
> By default, the fltk common dialogs use a hotspot mechanism..

Yes; see fl_message_hotspot() under the "common dialogs classes and functions"
section of the docs:
http://www.fltk.org/doc-1.3/group__group__comdlg.html#ga5cb8a823f404d44994862d198b3a82b1

On my system, AFAIK the window manager does no auto-window placement.

If I run the test/ask program:

> The first window opens exactly center screen,
regardless of where the mouse is.

> Clicking "Test text", the resulting input dialog
always opens with the "cancel" button under the mouse,
wherever the mouse is.

> On the first window if I click the 'X' to close the window,
the "Are you sure you want to quit" dialog opens, which has
hotspots disabled, and seems to open wherever I opened the
last "Test text" dialog. (If I run the program fresh and click
the 'X', this dialog opens at the extreme upper left of the
window manager, i.e. x/y=0,0 on the root window)

Some window managers try to diagonally stack windows that are open
one after the other. Mine does not; I can tell because if I run
the test/ask program 10 times in the background, all 10 windows
open up center screen. The ask program's first window is created
with no x+y position, just a w+h.

Reply all
Reply to author
Forward
0 new messages