# Candidate list appearing at the wrong coordinates

**URL:** <https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862>\
**Category:** SDL Development\
**Created:** [July 27, 2014, 3:40am UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862 "2014-07-27T03:40:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [July 27, 2014, 3:40am UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/1 "2014-07-27T03:40:29Z")

</div>

Having problems implementing IME support in my game. While I know  
support for it in Linux is already flaky (candidate list will get  
hidden in fullscreen mode), I thought I should still work on the parts  
that do work (i.e. windowed mode). So this happened:

[![](https://i.imgur.com/N5ubxjC.png) ](https://i.imgur.com/N5ubxjC.png)

The code responsible for this mess:------------------------------------------------------------  
int list\_x = x;  
int list\_y = FILE\_NAME\_Y2;  
virtual\_to\_real\_coord(&list\_x, &list\_y);

```
  SDL_Rect list_rect;
  list_rect.x = list_x;
  list_rect.y = list_y;
  list_rect.w = 1;
  list_rect.h = 1;

  SDL_SetTextInputRect(&list_rect);

```

* * *

Yes, I did think that maybe coordinates are being calculated wrong, so  
I checked where the list ended up in the screenshot to make sure. It  
seems like the calculations are correct, but the list position is  
relative to the window frame, not the inside (so the main reason it  
appears higher than it should is that the titlebar is heavily skewing  
the position - if the frame was thicker it would also appear  
noticeably shifted to the left).

So the solution seems obvious: offset the coordinates so they’re  
relative to the window contents and not the frame. Should SDL be doing  
it itself or should I be doing it on my own? (probably the former) If  
the latter, how do I get the window frame size? (in a  
platform-independent way, that is)

---

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [July 27, 2014, 4:03am UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/2 "2014-07-27T04:03:04Z")

</div>

Random thought that just came up on Twitter: this may be actually  
ibus’ fault again (since window coordinates in X should not include  
the frame, as the frame is added by window managers). Not sure how  
much can SDL do about this.

Between that and the list not working in fullscreen because it’s not  
topmost, I’m seriously starting to think that SDL should allow being  
able to take control over the list (either that or handle the list  
itself). How feasible is that? (aware that this wouldn’t make it to  
2.0.4)

---

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [July 27, 2014, 8:08am UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/3 "2014-07-27T08:08:57Z")

</div>

## OK, looking at the ibus code (spent hours trying to look at the SDL code for possible workarounds) I found this:------------------------------------------------------------ int x = 0, y = 0; SDL\_GetWindowPosition(focused\_win, &x, &y); x += ibus\_cursor\_rect.x; y += ibus\_cursor\_rect.y;

So it looks like ibus takes absolute screen coordinates (in other  
words, not ibus’ fault after all). This means SDL\_GetWindowPosition is  
returning the position of the window with frame included, but the code  
is ignoring that there’s a frame to deal with. This probably needs to  
be changed.

2014-07-27 1:03 GMT-03:00, Sik the hedgehog \<@Sik\_the\_hedgehog\>:

> Random thought that just came up on Twitter: this may be actually  
> ibus’ fault again (since window coordinates in X should not include  
> the frame, as the frame is added by window managers). Not sure how  
> much can SDL do about this.
> 
> Between that and the list not working in fullscreen because it’s not  
> topmost, I’m seriously starting to think that SDL should allow being  
> able to take control over the list (either that or handle the list  
> itself). How feasible is that? (aware that this wouldn’t make it to  
> 2.0.4)

---

<div class="post-metadata">

**Author:** ![Alex\_Baines](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_baines/32/2606_2.png) [@Alex\_Baines](https://discourse.libsdl.org/u/Alex_Baines)\
**Post date:** [July 27, 2014, 2:40pm UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/4 "2014-07-27T14:40:54Z")

</div>

I will look into this.On 27/07/14 09:08, Sik the hedgehog wrote:

> OK, looking at the ibus code (spent hours trying to look at the SDL  
> code for possible workarounds) I found this:
> 
> * * *
> 
> ```
> int x = 0, y = 0;
> SDL_GetWindowPosition(focused_win, &x, &y);
> x += ibus_cursor_rect.x;
> y += ibus_cursor_rect.y;
> 
> ```
> 
> * * *
> 
> So it looks like ibus takes absolute screen coordinates (in other  
> words, not ibus’ fault after all). This means SDL\_GetWindowPosition is  
> returning the position of the window with frame included, but the code  
> is ignoring that there’s a frame to deal with. This probably needs to  
> be changed.
> 
> 2014-07-27 1:03 GMT-03:00, Sik the hedgehog \<sik.the.hedgehog at [gmail.com](http://gmail.com)\>:
> 
> > Random thought that just came up on Twitter: this may be actually  
> > ibus’ fault again (since window coordinates in X should not include  
> > the frame, as the frame is added by window managers). Not sure how  
> > much can SDL do about this.
> > 
> > Between that and the list not working in fullscreen because it’s not  
> > topmost, I’m seriously starting to think that SDL should allow being  
> > able to take control over the list (either that or handle the list  
> > itself). How feasible is that? (aware that this wouldn’t make it to  
> > 2.0.4)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Alex\_Baines](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_baines/32/2606_2.png) [@Alex\_Baines](https://discourse.libsdl.org/u/Alex_Baines)\
**Post date:** [July 27, 2014, 3:51pm UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/5 "2014-07-27T15:51:45Z")

</div>

Ok, I have fixed this here: [A few small issues with the Ibus IME code · Issue #1583 · libsdl-org/SDL · GitHub](https://bugzilla.libsdl.org/show_bug.cgi?id=2662)

I’ve also fixed the variable shadowing and another separate bug where  
you wouldn’t get an editing event when the user presses backspace enough  
times to close the list.On 27/07/14 15:40, Alex Baines wrote:

> I will look into this.
> 
> On 27/07/14 09:08, Sik the hedgehog wrote:
> 
> > OK, looking at the ibus code (spent hours trying to look at the SDL  
> > code for possible workarounds) I found this:
> > 
> > * * *
> > 
> > ```
> > int x = 0, y = 0;
> > SDL_GetWindowPosition(focused_win, &x, &y);
> > x += ibus_cursor_rect.x;
> > y += ibus_cursor_rect.y;
> > 
> > ```
> > 
> > * * *
> > 
> > So it looks like ibus takes absolute screen coordinates (in other  
> > words, not ibus’ fault after all). This means SDL\_GetWindowPosition is  
> > returning the position of the window with frame included, but the code  
> > is ignoring that there’s a frame to deal with. This probably needs to  
> > be changed.
> > 
> > 2014-07-27 1:03 GMT-03:00, Sik the hedgehog \<sik.the.hedgehog at [gmail.com](http://gmail.com)\>:
> > 
> > > Random thought that just came up on Twitter: this may be actually  
> > > ibus’ fault again (since window coordinates in X should not include  
> > > the frame, as the frame is added by window managers). Not sure how  
> > > much can SDL do about this.
> > > 
> > > Between that and the list not working in fullscreen because it’s not  
> > > topmost, I’m seriously starting to think that SDL should allow being  
> > > able to take control over the list (either that or handle the list  
> > > itself). How feasible is that? (aware that this wouldn’t make it to  
> > > 2.0.4)
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [July 27, 2014, 5:26pm UTC](https://discourse.libsdl.org/t/candidate-list-appearing-at-the-wrong-coordinates/20862/6 "2014-07-27T17:26:11Z")

</div>

Just tested it, I can confirm it works (ignore the lack of placeholder  
text, that’s because I didn’t add code to draw it yet):

[http://i.imgur.com/N48UKpA.png](http://i.imgur.com/N48UKpA.png)

2014-07-27 12:51 GMT-03:00, Alex Baines :\> Ok, I have fixed this here:

> [A few small issues with the Ibus IME code · Issue #1583 · libsdl-org/SDL · GitHub](https://bugzilla.libsdl.org/show_bug.cgi?id=2662)
> 
> I’ve also fixed the variable shadowing and another separate bug where  
> you wouldn’t get an editing event when the user presses backspace enough  
> times to close the list.
> 
> On 27/07/14 15:40, Alex Baines wrote:
> 
> > I will look into this.
> > 
> > On 27/07/14 09:08, Sik the hedgehog wrote:
> > 
> > > OK, looking at the ibus code (spent hours trying to look at the SDL  
> > > code for possible workarounds) I found this:
> > > 
> > > * * *
> > > 
> > > ```
> > > int x = 0, y = 0;
> > > SDL_GetWindowPosition(focused_win, &x, &y);
> > > x += ibus_cursor_rect.x;
> > > y += ibus_cursor_rect.y;
> > > 
> > > ```
> > > 
> > > * * *
> > > 
> > > So it looks like ibus takes absolute screen coordinates (in other  
> > > words, not ibus’ fault after all). This means SDL\_GetWindowPosition is  
> > > returning the position of the window with frame included, but the code  
> > > is ignoring that there’s a frame to deal with. This probably needs to  
> > > be changed.
> > > 
> > > 2014-07-27 1:03 GMT-03:00, Sik the hedgehog  
> > > \<@Sik\_the\_hedgehog\>:
> > > 
> > > > Random thought that just came up on Twitter: this may be actually  
> > > > ibus’ fault again (since window coordinates in X should not include  
> > > > the frame, as the frame is added by window managers). Not sure how  
> > > > much can SDL do about this.
> > > > 
> > > > Between that and the list not working in fullscreen because it’s not  
> > > > topmost, I’m seriously starting to think that SDL should allow being  
> > > > able to take control over the list (either that or handle the list  
> > > > itself). How feasible is that? (aware that this wouldn’t make it to  
> > > > 2.0.4)
> > > 
> > > * * *
> > > 
> > > SDL mailing list  
> > > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
