# Two Windows and ci::app::App::get()-\>getWindowSize()

**URL:** <https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113>\
**Category:** Using Cinder\
**Created:** [June 24, 2016, 5:03pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113 "2016-06-24T17:03:05Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 24, 2016, 5:03pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/1 "2016-06-24T17:03:05Z")

</div>

Hey Embers,

I couldn’t figure out why, for the life of me, the getWindowSize() call was yielding differing values at seemingly random until I finally realized that the fact that I have two windows could influence this particular call. Two windows - D’uh - I know. I just (mistakenly) assumed it was always the primary window this particular call would refer to. And just to complete the story I’d honestly forgotten all about the secondary window given that I currently rarely use it. But rest assured I do plan to - in the future.

Cinders innards are still a little nebulous to me, so I’m wondering if someone has dealt with this before and knows of a method in cinder to indicate which window to let this (and similar function calls) refer to, if you have more than one window.

I know an option would be to pass around a reference to the window in question. For now, this is an approach I’d like to avoid.

Much obliged,  
Gazoo

---

<div class="post-metadata">

**Author:** ![sharkbox](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sharkbox/32/39_2.png) [@sharkbox](https://discourse.libcinder.org/u/sharkbox)\
**Post date:** [June 24, 2016, 5:39pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/2 "2016-06-24T17:39:01Z")

</div>

Cinder has a function that lets you choose which window you’re referring to.

`ci::app::WindowRef winRef = getWindowIndex(0);`  
Which accepts an number between 0 and `getNumWindows()`

From here you can call normal functions on the window like  
`winRef->getWidth();`  
or anything else listed in the docs. ([https://libcinder.org/docs/classcinder\_1\_1app\_1\_1\_window.html](https://libcinder.org/docs/classcinder_1_1app_1_1_window.html))

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [June 24, 2016, 9:27pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/3 "2016-06-24T21:27:14Z")

</div>

If you’re checking the window size from the virtual App::draw() method, yes that will get called once per window, but if you instead register your draw method with the window-\>getSignalDraw(), that will only be called for the respective window and you’ll always get the expected window size.

I believe that in App::update(), calling getWindow() will always return the primary window.

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 25, 2016, 11:41am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/4 "2016-06-25T11:41:29Z")

</div>

@sharkbox - Fantastic, that’s exactly what I was looking for. If you were standing next to me now, I’d give you a high five.

@rich.e - I’m slightly confused by your statements. Are you saying that if I have 2 window and call `getWindowSize()` in the `App::draw()` method it’ll return alternating values? From what you’d wrote I’d almost think you’re saying it would be called twice which I don’t quite understand.

Furthermore, I think I can confirm that calling `getWindow()` in the `App::update()` function does not necessarily yield the primary window. The following two calls:

> CI\_LOG\_I( " ci::app::App::get()-\>getWindowSize() " \<\< ci::app::App::get()-\>getWindowSize() );  
> CI\_LOG\_I( " ci::app::App::get()-\>getWindow().get()-\>getSize() " \<\< ci::app::App::get()-\>getWindow().get()-\>getSize() );

called inside of an object (called from within `App::update()` yield a size pertaining to the secondary window.

---

<div class="post-metadata">

**Author:** ![sansumbrella](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sansumbrella/32/30_2.png) [@sansumbrella](https://discourse.libcinder.org/u/sansumbrella)\
**Post date:** [June 28, 2016, 6:06pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/5 "2016-06-28T18:06:53Z")

</div>

`draw` will be called once for each window. So if you have two windows, it will be called twice per frame. You read it right, Rich is explicitly saying that App::draw will be called twice.

If you want to have some other drawing functions called specific to a window, you can connect to that window’s draw signal.

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 28, 2016, 6:38pm UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/6 "2016-06-28T18:38:37Z")

</div>

@sansumbrella My confusion stems from the fact that grammatically, @rich.e, seemed to be referring to the function to check the window size being called twice and not `App::draw()`.

I think I’ve got the hang of the situation now thou - thanks for following up.

---

<div class="post-metadata">

**Author:** ![DaniCo](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@DaniCo](https://discourse.libcinder.org/u/DaniCo)\
**Post date:** [August 2, 2016, 1:12am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/7 "2016-08-02T01:12:02Z")

</div>

I’m having trouble connecting my drawing function to a specific window, I noticed on old posts (2-3 years old) that there was a connectDraw() that could link the functions to a window but I can’t find it anywhere in the documentation.

How can I do this? any guidance is greatly appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [August 2, 2016, 2:21am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/8 "2016-08-02T02:21:21Z")

</div>

Take a look at the `app::Window`'s [`getSignalDraw()` method](https://github.com/cinder/Cinder/blob/bded11591a938f3c80879f506f8a173244be6ecb/include/cinder/app/Window.h#L387).

---

<div class="post-metadata">

**Author:** ![sansumbrella](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sansumbrella/32/30_2.png) [@sansumbrella](https://discourse.libcinder.org/u/sansumbrella)\
**Post date:** [August 2, 2016, 2:21am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/9 "2016-08-02T02:21:38Z")

</div>

The signals for different events emitted by Cinder are now accessed through a more consistent `getSignal*()` interface. Windows have signals for various user input events as well as draw.

e.g.

```auto
getWindow(0)->getSignalDraw().connect([this] { drawFirstWindow(); });

```

---

<div class="post-metadata">

**Author:** ![DaniCo](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@DaniCo](https://discourse.libcinder.org/u/DaniCo)\
**Post date:** [August 2, 2016, 2:56am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/10 "2016-08-02T02:56:04Z")

</div>

@sansumbrella & @rich.e Thank you very much !

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [March 25, 2017, 5:54am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/11 "2017-03-25T05:54:40Z")

</div>

Hey people,

Just a short follow up on this matter. I’ve recently happened upon another issue caused by the getWindowSize() function. In the Cinder’s source the following text can be found:

```
> //! Returns the size of the App's current window measured in points
> ivec2 getWindowSize() const { return ivec2( getWindowWidth(), getWindowHeight() ); }

```

My current understanding is that outside of the draw calls, you also cannot depend on this function to yield the size of the active window (which is what I interpret from **current** window). In my application, I have the main window focused, but calling this function like so:

`ci::app::App::get()->getWindowSize();`

Will yield the size of my other window. The text should be updated in the Cinder source I’d say, no?

Regards,  
Gazoo

---

<div class="post-metadata">

**Author:** ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)\
**Post date:** [March 25, 2017, 6:08am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/12 "2017-03-25T06:08:22Z")

</div>

Hi,

Usually I store references to the windows and call the `getWindowSize` on the references. It is not prone to the state dependent errors.

Bala.

---

<div class="post-metadata">

**Author:** ![pholz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/pholz/32/322_2.png) [@pholz](https://discourse.libcinder.org/u/pholz)\
**Post date:** [March 29, 2017, 7:13am UTC](https://discourse.libcinder.org/t/two-windows-and-ci-app-app-get-getwindowsize/113/13 "2017-03-29T07:13:11Z")

</div>

I am using the approach of the `BasicAppMultiWindow` sample, saving the index or name of my window with `setUserData()`. Then I make a simple case distinction in the `draw()` function, and `getWindowWidth()` etc always yield the expected results.
