Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WindowBase::setImePreEditPosition #2469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/SFML/Window/WindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,23 @@ class SFML_WINDOW_API WindowBase
////////////////////////////////////////////////////////////
bool hasFocus() const;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit popup
/// should show up
///
/// The position specified is relative to the left-top
/// corner of the window area.
///
/// It is implementation-specific what happens when negative
/// values are used. X11 handles them as you would expect,
/// but Windows sometimes resets the position to the top-left
/// of the screen.
///
/// \param position Left-top corner of the preedit popup
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position);

////////////////////////////////////////////////////////////
/// \brief Get the OS-specific handle of the window
///
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ bool WindowImplAndroid::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::setImePreEditPosition(const Vector2i& /* position */)
{
// Not applicable
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::forwardEvent(const Event& event)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ class WindowImplAndroid : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

static void forwardEvent(const Event& event);
static WindowImplAndroid* singleInstance;

Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Window/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ if(SFML_OS_LINUX)
find_package(UDev REQUIRED)
target_link_libraries(sfml-window PRIVATE UDev::UDev dl)
elseif(SFML_OS_WINDOWS)
target_link_libraries(sfml-window PRIVATE winmm gdi32)
target_link_libraries(sfml-window PRIVATE winmm gdi32 imm32)
elseif(SFML_OS_FREEBSD)
target_link_libraries(sfml-window PRIVATE usbhid)
elseif(SFML_OS_MACOS)
Expand Down
8 changes: 8 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ bool WindowImplDRM::hasFocus() const
return true;
}


////////////////////////////////////////////////////////////
void WindowImplDRM::setImePreEditPosition(const Vector2i& /* position */)
{
// Not applicable
}


void WindowImplDRM::processEvents()
{
sf::Event ev;
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ class WindowImplDRM : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

protected:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
10 changes: 10 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,16 @@ bool WindowImplX11::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowImplX11::setImePreEditPosition(const Vector2i& position)
{
const XPoint xpos{static_cast<short>(position.x), static_cast<short>(position.y)};
const XVaNestedList preeditAttr = XVaCreateNestedList(0, XNSpotLocation, &xpos, NULL);
XSetICValues(m_inputContext, XNPreeditAttributes, preeditAttr, NULL);
XFree(preeditAttr);
}


////////////////////////////////////////////////////////////
void WindowImplX11::grabFocus()
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ class WindowImplX11 : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

protected:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
17 changes: 16 additions & 1 deletion src/SFML/Window/Win32/WindowImplWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,21 @@ bool WindowImplWin32::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowImplWin32::setImePreEditPosition(const Vector2i& position)
{
if (HIMC himc = ImmGetContext(m_handle); himc != nullptr)
{
COMPOSITIONFORM cf;
cf.ptCurrentPos.x = static_cast<LONG>(position.x);
cf.ptCurrentPos.y = static_cast<LONG>(position.y);
cf.dwStyle = CFS_FORCE_POSITION; // Don't let the IME adjust the position
ImmSetCompositionWindow(himc, &cf);
ImmReleaseContext(m_handle, himc);
}
}


////////////////////////////////////////////////////////////
void WindowImplWin32::registerWindowClass()
{
Expand Down Expand Up @@ -671,7 +686,7 @@ Keyboard::Scancode WindowImplWin32::toScancode(WPARAM wParam, LPARAM lParam)
case 86: return Keyboard::Scan::NonUsBackslash;
case 87: return Keyboard::Scan::F11;
case 88: return Keyboard::Scan::F12;

case 91: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::LSystem : Keyboard::Scan::Unknown;
case 92: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::RSystem : Keyboard::Scan::Unknown;
case 93: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::Menu : Keyboard::Scan::Unknown;
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Win32/WindowImplWin32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ class WindowImplWin32 : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

protected:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
8 changes: 8 additions & 0 deletions src/SFML/Window/WindowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ bool WindowBase::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowBase::setImePreEditPosition(const Vector2i& position)
{
if (m_impl)
m_impl->setImePreEditPosition(position);
}


////////////////////////////////////////////////////////////
WindowHandle WindowBase::getNativeHandle() const
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/WindowImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ class WindowImpl
////////////////////////////////////////////////////////////
virtual bool hasFocus() const = 0;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
virtual void setImePreEditPosition(const Vector2i& position) = 0;

////////////////////////////////////////////////////////////
/// \brief Create a Vulkan rendering surface
///
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/iOS/WindowImplUIKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ class WindowImplUIKit : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

////////////////////////////////////////////////////////////
/// \brief Notify an event
///
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/iOS/WindowImplUIKit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@
}


////////////////////////////////////////////////////////////
void WindowImplUIKit::setImePreEditPosition(const Vector2i& /* position */)
{
// Not applicable
}


////////////////////////////////////////////////////////////
void WindowImplUIKit::forwardEvent(Event event)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/macOS/WindowImplCocoa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ class WindowImplCocoa : public WindowImpl
////////////////////////////////////////////////////////////
bool hasFocus() const override;

////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;

protected:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/macOS/WindowImplCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,11 @@ void showMouseCursor()
}


////////////////////////////////////////////////////////////
void WindowImplCocoa::setImePreEditPosition(const Vector2i& /* position */)
{
// TODO: To implement
}


} // namespace sf::priv