Skip to content

Commit d50a91b

Browse files
author
Raphael Dumusc
authored
Merge pull request #112 from rdumusc/master
DesktopStreamer: OSX multi-window is a view option, other UI improvements
2 parents 23f6047 + 50149ba commit d50a91b

File tree

7 files changed

+244
-140
lines changed

7 files changed

+244
-140
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Daniel Nachbaur <[email protected]>
55

66
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
7-
project(Deflect VERSION 0.11.0)
7+
project(Deflect VERSION 0.11.1)
88
set(Deflect_VERSION_ABI 4)
99

1010
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake

apps/DesktopStreamer/CMakeLists.txt

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(DESKTOPSTREAMER_SOURCES
1818
set(DESKTOPSTREAMER_LINK_LIBRARIES
1919
Deflect
2020
Qt5::Core
21+
Qt5::Network
2122
Qt5::Widgets
2223
)
2324

@@ -36,12 +37,11 @@ if(APPLE)
3637
list(APPEND DESKTOPSTREAMER_SOURCES AppNapSuspender.mm)
3738
list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework Foundation")
3839
if(TARGET Qt5::MacExtras)
39-
option(DESKTOPSTREAMER_ENABLE_MULTIWINDOW "Enable support for streaming multiple windows" OFF)
40-
if(DESKTOPSTREAMER_ENABLE_MULTIWINDOW)
41-
list(APPEND DESKTOPSTREAMER_SOURCES DesktopWindowsModel.mm)
42-
list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES
43-
Qt5::MacExtras "-framework AppKit")
44-
endif()
40+
list(APPEND DESKTOPSTREAMER_HEADERS DesktopWindowsModel.h)
41+
list(APPEND DESKTOPSTREAMER_SOURCES DesktopWindowsModel.mm)
42+
list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES
43+
Qt5::MacExtras "-framework AppKit"
44+
)
4545
endif()
4646
if(OSX_VERSION VERSION_LESS 10.9)
4747
list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework ApplicationServices")
@@ -55,9 +55,6 @@ endif()
5555
common_application(${DESKTOPSTREAMER_APP_NAME} GUI)
5656

5757
if(APPLE)
58-
if(TARGET Qt5::MacExtras AND DESKTOPSTREAMER_ENABLE_MULTIWINDOW)
59-
target_compile_definitions(${DESKTOPSTREAMER_APP_NAME} PRIVATE DESKTOPSTREAMER_ENABLE_MULTIWINDOW)
60-
endif()
6158
# create a zip for Puppet deployment
6259
install(CODE "execute_process(COMMAND zip -r
6360
${DESKTOPSTREAMER_APP_NAME}-${PROJECT_VERSION}.zip ${DESKTOPSTREAMER_APP_NAME}.app

apps/DesktopStreamer/MainWindow.cpp

+119-59
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include <deflect/version.h>
4545

46+
#include <QHostInfo>
4647
#include <QMessageBox>
4748
#include <QPainter>
4849
#include <QScreen>
@@ -56,37 +57,38 @@ typedef __int32 int32_t;
5657
# include <windows.h>
5758
#else
5859
# include <stdint.h>
59-
# include <unistd.h>
6060
#endif
6161

62-
#ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
62+
#ifdef DEFLECT_USE_QT5MACEXTRAS
6363
# include "DesktopWindowsModel.h"
6464
#endif
6565

6666
#define SHARE_DESKTOP_UPDATE_DELAY 0
6767
#define FAILURE_UPDATE_DELAY 100
6868
#define FRAME_RATE_DAMPING 0.1f // influence of new value between 0-1
6969

70+
namespace
71+
{
7072
const std::vector< std::pair< QString, QString > > defaultHosts = {
7173
{ "DisplayWall Ground floor", "bbpav02.epfl.ch" },
7274
{ "DisplayWall 3rd floor", "bbpav04.epfl.ch" },
7375
{ "DisplayWall 5th floor", "bbpav05.epfl.ch" },
7476
{ "DisplayWall 6th floor", "bbpav06.epfl.ch" }
7577
};
76-
78+
const QString streamButtonDefaultText = "Stream";
7779
const QString streamSelected = "Stream selected item(s)";
80+
}
7881

7982
MainWindow::MainWindow()
8083
: _streamID( 0 )
8184
, _averageUpdate( 0 )
8285
{
8386
setupUi( this );
8487

85-
#ifndef __APPLE__
86-
// Event injection support is currently limited to OSX
87-
_remoteControlLabel->setVisible( false );
88-
_remoteControlCheckBox->setVisible( false );
89-
#endif
88+
for( const auto& entry : defaultHosts )
89+
_hostComboBox->addItem( entry.first, entry.second );
90+
91+
_hostComboBox->setCurrentIndex( -1 ); // no default host selected initially
9092

9193
connect( _hostComboBox, &QComboBox::currentTextChanged,
9294
[&]( const QString& text )
@@ -95,47 +97,42 @@ MainWindow::MainWindow()
9597
_listView->setEnabled( !text.isEmpty( ));
9698
});
9799

98-
for( const auto& entry : defaultHosts )
99-
_hostComboBox->addItem( entry.first, entry.second );
100-
101-
// no default host selected initially
102-
_hostComboBox->setCurrentIndex( -1 );
100+
_streamIdLineEdit->setText( QHostInfo::localHostName( ));
103101

104-
char hostname[256] = { 0 };
105-
gethostname( hostname, 256 );
106-
_streamIdLineEdit->setText( QString( "%1" ).arg( hostname ));
107-
108-
#ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
109-
_listView->setModel( new DesktopWindowsModel );
110-
111-
// select 'Desktop' item as initial default stream item
112-
_listView->setCurrentIndex( _listView->model()->index( 0, 0 ));
113-
_streamButton->setText( streamSelected );
114-
115-
const int itemsHorizontal = std::min( 3.f,
116-
std::ceil( std::sqrt( float(_listView->model()->rowCount( )))));
117-
const int itemsVertical = std::min( 3.f,
118-
std::ceil(float( _listView->model()->rowCount( )) / itemsHorizontal ));
119-
120-
// 230 (itemSize + spacing), frameWidth for decorations
121-
resize( QSize( 230 * itemsHorizontal + 2 * _listView->frameWidth(),
122-
230 * itemsVertical + 2 * _listView->frameWidth() + 50 ));
123-
#else
124-
_listView->setHidden( true );
125-
adjustSize();
126-
#endif
102+
connect( _streamButton, &QPushButton::clicked,
103+
this, &MainWindow::_update );
104+
connect( _streamButton, &QPushButton::clicked,
105+
_actionMultiWindowMode, &QAction::setDisabled );
127106

128107
connect( _remoteControlCheckBox, &QCheckBox::clicked,
129108
this, &MainWindow::_onStreamEventsBoxClicked );
130109

131-
connect( _streamButton, &QPushButton::clicked,
132-
this, &MainWindow::_update );
110+
connect( _actionAdvancedSettings, &QAction::triggered,
111+
this, &MainWindow::_showAdvancedSettings );
112+
113+
connect( _actionMultiWindowMode, &QAction::triggered,
114+
[this]( const bool checked )
115+
{
116+
if( checked )
117+
_showMultiWindowMode();
118+
else
119+
_showSingleWindowMode();
120+
});
133121

134122
connect( _actionAbout, &QAction::triggered,
135123
this, &MainWindow::_openAboutWidget );
136124

137-
// Update timer
138125
connect( &_updateTimer, &QTimer::timeout, this, &MainWindow::_update );
126+
127+
#ifndef __APPLE__
128+
// Event injection support is currently limited to OSX
129+
_showRemoteControl( false );
130+
#endif
131+
#ifndef DEFLECT_USE_QT5MACEXTRAS
132+
_actionMultiWindowMode->setVisible( false );
133+
#endif
134+
_showAdvancedSettings( false );
135+
_showSingleWindowMode();
139136
}
140137

141138
MainWindow::~MainWindow() {}
@@ -193,11 +190,69 @@ void MainWindow::_update()
193190
_stopStreaming();
194191
}
195192

193+
void MainWindow::_showRemoteControl( const bool visible )
194+
{
195+
_remoteControlLabel->setVisible( visible );
196+
_remoteControlCheckBox->setVisible( visible );
197+
}
198+
199+
void MainWindow::_showMultiWindowMode()
200+
{
201+
#ifdef DEFLECT_USE_QT5MACEXTRAS
202+
if( !_listView->model( ))
203+
{
204+
auto model = new DesktopWindowsModel();
205+
model->setParent( _listView );
206+
_listView->setModel( model );
207+
}
208+
209+
_listView->setVisible( true );
210+
211+
// select 'Desktop' item as initial default stream item
212+
_listView->setCurrentIndex( _listView->model()->index( 0, 0 ));
213+
_streamButton->setText( streamSelected );
214+
215+
const int itemsHorizontal = std::min( 3.f,
216+
std::ceil( std::sqrt( float(_listView->model()->rowCount( )))));
217+
const int itemsVertical = std::min( 3.f,
218+
std::ceil(float( _listView->model()->rowCount( )) / itemsHorizontal ));
219+
220+
layout()->setSizeConstraint( QLayout::SetDefaultConstraint );
221+
setFixedSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
222+
// 230 (itemSize + spacing), frameWidth for decorations
223+
resize( QSize( 230 * itemsHorizontal + 2 * _listView->frameWidth(),
224+
230 * itemsVertical + 2 * _listView->frameWidth() + 50 ));
225+
#endif
226+
}
227+
228+
void MainWindow::_showSingleWindowMode()
229+
{
230+
_listView->setHidden( true );
231+
_streamButton->setText( streamButtonDefaultText );
232+
233+
layout()->setSizeConstraint( QLayout::SetFixedSize );
234+
}
235+
236+
void MainWindow::_showAdvancedSettings( const bool visible )
237+
{
238+
_maxFrameRateSpinBox->setVisible( visible );
239+
_maxFrameRateLabel->setVisible( visible );
240+
241+
_streamIdLineEdit->setVisible( visible );
242+
_streamIdLabel->setVisible( visible );
243+
}
244+
196245
void MainWindow::_updateStreams()
197246
{
198-
const std::string& host = _getStreamHost();
247+
if( _actionMultiWindowMode->isChecked( ))
248+
_updateMultipleStreams();
249+
else
250+
_updateSingleStream();
251+
}
199252

200-
#ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
253+
void MainWindow::_updateMultipleStreams()
254+
{
255+
#ifdef DEFLECT_USE_QT5MACEXTRAS
201256
const QModelIndexList windowIndices =
202257
_listView->selectionModel()->selectedIndexes();
203258

@@ -219,12 +274,12 @@ void MainWindow::_updateStreams()
219274
const int pid = index.isValid() ?
220275
_listView->model()->data( index,
221276
DesktopWindowsModel::ROLE_PID).toInt(): 0;
277+
const std::string host = _getStreamHost();
222278
StreamPtr stream( new Stream( *this, index, streamId, host, pid ));
223279

224280
if( !stream->isConnected( ))
225281
{
226-
_statusbar->showMessage( QString( "Could not connect to host %1" ).
227-
arg( host.c_str( )));
282+
_showConnectionErrorStatus();
228283
continue;
229284
}
230285

@@ -240,9 +295,11 @@ void MainWindow::_updateStreams()
240295
_streamButton->setChecked( true );
241296
_startStreaming();
242297
};
298+
#endif
299+
}
243300

244-
#else // No window list: Stream button toggles
245-
301+
void MainWindow::_updateSingleStream()
302+
{
246303
if( !_streamButton->isChecked( ))
247304
{
248305
_stopStreaming();
@@ -254,7 +311,7 @@ void MainWindow::_updateStreams()
254311
const QPersistentModelIndex index; // default == use desktop
255312
StreamPtr stream( new Stream( *this, index,
256313
_streamIdLineEdit->text().toStdString(),
257-
host ));
314+
_getStreamHost( )));
258315
if( stream->isConnected( ))
259316
{
260317
if( _remoteControlCheckBox->isChecked( ))
@@ -263,9 +320,14 @@ void MainWindow::_updateStreams()
263320
_startStreaming();
264321
}
265322
else
266-
_statusbar->showMessage( "Could not connect to host" );
323+
_showConnectionErrorStatus();
267324
}
268-
#endif
325+
}
326+
327+
void MainWindow::_showConnectionErrorStatus()
328+
{
329+
_statusbar->showMessage( QString( "Cannot connect to host: '%1'" ).
330+
arg( _getStreamHost().c_str( )));
269331
}
270332

271333
void MainWindow::_processStreamEvents()
@@ -306,22 +368,20 @@ void MainWindow::_shareDesktopUpdate()
306368
}
307369
}
308370

309-
#ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
310371
void MainWindow::_deselect( ConstStreamPtr stream )
311372
{
312-
const QPersistentModelIndex& index = stream->getIndex();
313-
if( index.isValid( ))
373+
if( _actionMultiWindowMode->isChecked( ))
314374
{
315-
QItemSelectionModel* model = _listView->selectionModel();
316-
model->select( index, QItemSelectionModel::Deselect );
375+
const QPersistentModelIndex& index = stream->getIndex();
376+
if( index.isValid( ))
377+
{
378+
QItemSelectionModel* model = _listView->selectionModel();
379+
model->select( index, QItemSelectionModel::Deselect );
380+
}
317381
}
382+
else
383+
_streamButton->setChecked( false );
318384
}
319-
#else
320-
void MainWindow::_deselect( ConstStreamPtr )
321-
{
322-
_streamButton->setChecked( false );
323-
}
324-
#endif
325385

326386
void MainWindow::_regulateFrameRate()
327387
{

apps/DesktopStreamer/MainWindow.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
/* or implied, of The University of Texas at Austin. */
3939
/*********************************************************************/
4040

41-
#ifndef MAIN_WINDOW_H
42-
#define MAIN_WINDOW_H
41+
#ifndef MAINWINDOW_H
42+
#define MAINWINDOW_H
4343

4444
#include <apps/DesktopStreamer/ui_MainWindow.h>
4545

@@ -92,9 +92,19 @@ private slots:
9292
AppNapSuspender _napSuspender;
9393
#endif
9494

95+
void _showMultiWindowMode();
96+
void _showSingleWindowMode();
97+
98+
void _showRemoteControl( bool visible );
99+
void _showAdvancedSettings( bool visible );
100+
95101
void _startStreaming();
96102
void _stopStreaming();
97103
void _updateStreams();
104+
void _updateMultipleStreams();
105+
void _updateSingleStream();
106+
void _showConnectionErrorStatus();
107+
98108
void _deselect( ConstStreamPtr stream );
99109
void _processStreamEvents();
100110
void _shareDesktopUpdate();

0 commit comments

Comments
 (0)