Skip to content

Commit f1f65df

Browse files
committed
Supporting always-on-top and borderless in Linux now, with windowTest update to match
1 parent 6d87064 commit f1f65df

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/cinder/app/linux/WindowImplLinuxGlfw.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "cinder/app/linux/WindowImplLinux.h"
2626
#include "cinder/app/linux/AppImplLinux.h"
2727
#include "cinder/app/linux/PlatformLinux.h"
28-
#include "cinder/Log.h"
29-
3028
namespace cinder { namespace app {
3129

3230
WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux *sharedRendererWindow, AppImplLinux *appImpl )
@@ -74,6 +72,7 @@ WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux
7472
::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, minorVersion );
7573
::glfwWindowHint( GLFW_DECORATED, format.isBorderless() ? GL_FALSE : GL_TRUE );
7674
::glfwWindowHint( GLFW_RESIZABLE, format.isResizable() ? GL_TRUE : GL_FALSE );
75+
::glfwWindowHint( GLFW_FLOATING, format.isAlwaysOnTop() ? GL_TRUE : GL_FALSE );
7776
if( options.getCoreProfile() ) {
7877
::glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
7978
std::cout << "Rendering with OpenGL Core Profile " << majorVersion << "." << minorVersion << std::endl;
@@ -105,6 +104,9 @@ WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux
105104
mWindowRef = Window::privateCreate__( this, mAppImpl->getApp() );
106105

107106
mAppImpl->registerWindowEvents( this );
107+
108+
setBorderless( format.isBorderless() );
109+
setAlwaysOnTop( format.isAlwaysOnTop() );
108110
}
109111

110112
WindowImplLinux::~WindowImplLinux()
@@ -188,14 +190,30 @@ const std::vector<TouchEvent::Touch>& WindowImplLinux::getActiveTouches() const
188190

189191
void WindowImplLinux::setBorderless( bool borderless )
190192
{
191-
CI_LOG_W( "Window::setBorderless() currently unimplemented in GLFW" );
192-
// TODO: Find a way to do this w/o recreating
193+
if( mBorderless == borderless )
194+
return;
195+
196+
#if ! defined( CINDER_HEADLESS )
197+
if( mGlfwWindow ) {
198+
::glfwSetWindowAttrib( mGlfwWindow, GLFW_DECORATED, borderless ? GLFW_FALSE : GLFW_TRUE );
199+
}
200+
#endif
201+
202+
mBorderless = borderless;
193203
}
194204

195205
void WindowImplLinux::setAlwaysOnTop( bool alwaysOnTop )
196206
{
197-
CI_LOG_W( "Window::setAlwaysOnTop() currently unimplemented in GLFW" );
198-
// TODO: Find a way to do this w/o recreating
207+
if( mAlwayOnTop == alwaysOnTop )
208+
return;
209+
210+
#if ! defined( CINDER_HEADLESS )
211+
if( mGlfwWindow ) {
212+
::glfwSetWindowAttrib( mGlfwWindow, GLFW_FLOATING, alwaysOnTop ? GLFW_TRUE : GLFW_FALSE );
213+
}
214+
#endif
215+
216+
mAlwayOnTop = alwaysOnTop;
199217
}
200218

201219
void WindowImplLinux::keyDown( const KeyEvent &event )

test/windowTest/src/windowTestApp.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,14 @@ void WindowTestApp::keyDown( KeyEvent event )
205205
getWindowIndex(0)->hide();
206206
}
207207
else if( event.getChar() == 'b' ) {
208-
getWindow()->setBorderless( ! getWindow()->isBorderless() );
208+
auto window = getWindow();
209+
window->setBorderless( ! window->isBorderless() );
210+
CI_LOG_V( "Borderless toggled, now: " << ( window->isBorderless() ? "true" : "false" ) );
209211
}
210212
else if( event.getChar() == 't' ) {
211-
getWindow()->setAlwaysOnTop( ! getWindow()->isAlwaysOnTop() );
213+
auto window = getWindow();
214+
window->setAlwaysOnTop( ! window->isAlwaysOnTop() );
215+
CI_LOG_V( "Always-on-top toggled, now: " << ( window->isAlwaysOnTop() ? "true" : "false" ) );
212216
}
213217
else if( event.getChar() == 's' ) {
214218
getWindow()->setBorderless();
@@ -245,9 +249,17 @@ void WindowTestApp::windowDraw()
245249

246250
glEnable( GL_LINE_SMOOTH );
247251
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
252+
253+
const auto window = getWindow();
254+
std::string info = "f : toggle fullscreen\n";
255+
info += "b : toggle borderless (current: " + std::string( window->isBorderless() ? "on" : "off" ) + ")\n";
256+
info += "t : toggle always-on-top (current: " + std::string( window->isAlwaysOnTop() ? "on" : "off" ) + ")\n";
257+
info += "h : hide/show\n";
258+
info += "s : span displays\n";
259+
gl::drawString( info, vec2( 12.0f, 12.0f ), ColorA( 1, 1, 1, 0.9f ) );
248260

249261
gl::begin( GL_LINE_STRIP );
250-
const vector<vec2> &points = getWindow()->getUserData<WindowData>()->mPoints;
262+
const vector<vec2> &points = window->getUserData<WindowData>()->mPoints;
251263
for( auto pointIter = points.begin(); pointIter != points.end(); ++pointIter ) {
252264
gl::vertex( *pointIter /*+ vec2( 0, getElapsedSeconds() )*/ );
253265
}

0 commit comments

Comments
 (0)