Skip to content

Commit

Permalink
Merge branch 'i3-workaround'
Browse files Browse the repository at this point in the history
this closes #3
  • Loading branch information
dannyedel committed Jul 31, 2015
2 parents b67c337 + aeafa47 commit 5ab6424
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ if( NOT "${DSPDFVIEWER_VERSION}" MATCHES "^$" )
add_definitions(-DDSPDFVIEWER_VERSION="${DSPDFVIEWER_VERSION}")
endif()

if( I3WORKAROUND_SHELLCODE )
add_definitions(-DI3WORKAROUND_SHELLCODE="${I3WORKAROUND_SHELLCODE}")
endif()

set(dspdfviewer_SRCS adjustedlink.cpp hyperlinkarea.cpp pdfpagereference.cpp pdfdocumentreference.cpp runtimeconfiguration.cpp renderutils.cpp renderthread.cpp renderingidentifier.cpp pagepart.cpp renderedpage.cpp pdfrenderfactory.cpp pdfviewerwindow.cpp dspdfviewer.cpp main.cpp)

Expand Down
9 changes: 9 additions & 0 deletions docs/dspdfviewer.1
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ unit is \fIpercent of second screen's total height\fR.

Default value 20.

.TP
.B \-\-i3\-workaround \fI<bool>\fR
This tries to ask the i3 window manager (by calling the i3-msg command) to move
the audience window to "the other screen".

This is considered an experimental feature and disabled by default.
Read the runtimeconfiguration.cpp source code for more info.


.SH CONTROLS
You can use the following controls while
.B dspdfviewer
Expand Down
24 changes: 22 additions & 2 deletions pdfviewerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ PDFViewerWindow::PDFViewerWindow(unsigned int monitor, PagePart myPart, bool sho
useHyperlinks(r.hyperlinkSupport()),
minimumPageNumber(0),
maximumPageNumber(65535),
myPart(myPart)
myPart(myPart),
runtimeConfiguration(r)
{
if ( ! enabled )
return;
Expand All @@ -76,7 +77,8 @@ PDFViewerWindow::PDFViewerWindow(unsigned int monitor, PagePart myPart, bool sho
this->slideClock->setVisible(r.showSlideClock());
this->presentationClock->setVisible(r.showPresentationClock());
}
reposition();

reposition(); // This will fullscreen on its own
}


Expand Down Expand Up @@ -333,6 +335,24 @@ void PDFViewerWindow::resizeEvent(QResizeEvent* resizeEvent)
QWidget::resizeEvent(resizeEvent);
DEBUGOUT << "Resize event" << resizeEvent;
DEBUGOUT << "Resized from" << resizeEvent->oldSize() << "to" << resizeEvent->size() << ", requesting re-render.";
static bool i3shellcode_executed = false;
if (
windowRole() == "Audience_Window" &&
runtimeConfiguration.i3workaround() &&
resizeEvent->spontaneous() &&
// i3 generates a spontaneous resize.
! i3shellcode_executed
// Make sure to do this only once
) {
QApplication::flush(); // Make sure the window has been painted
// This is the second screen. It has now been created.
// so we should call the i3 shellcode now
const std::string shellcode = runtimeConfiguration.i3workaround_shellcode();
DEBUGOUT << "Running i3 workaround shellcode" << shellcode.c_str();
int rc = std::system( shellcode.c_str() );
DEBUGOUT << "Return code of i3-workaround was" << rc ;
i3shellcode_executed=true;
}
emit rerenderRequested();
}

Expand Down
2 changes: 2 additions & 0 deletions pdfviewerwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class PDFViewerWindow : public QWidget, private Ui::Form
bool correntImageRendered;
PagePart myPart;

const RuntimeConfiguration runtimeConfiguration;

/** Display this image
*/
void displayImage(QImage image);
Expand Down
29 changes: 29 additions & 0 deletions runtimeconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
#define DSPDFVIEWER_VERSION "UNKNOWN"
#endif

#ifndef I3WORKAROUND_SHELLCODE
/* This will get executed once both windows are created, provided
* the user passed --i3-workaround=true via command line or configuration file.
*
* You can override the shellcode by providing -DI3WORKAROUND_SHELLCODE="your shellcode"
* at the cmake step.
*/
#define I3WORKAROUND_SHELLCODE "i3-msg '[class=\"Dspdfviewer\" window_role=\"Audience_Window\"] move to output right, fullscreen'"
#endif


using namespace std;
using namespace boost::program_options;

Expand Down Expand Up @@ -65,6 +76,14 @@ RuntimeConfiguration::RuntimeConfiguration(int argc, char** argv)
"Cache the PDF file into memory\n"
"Useful if you are editing the PDF file with latex while using the presenter software."
)
("i3-workaround",
value<bool>(&m_i3workaround)->default_value(false),
"Use i3 specific workaround: Execute shellcode once both windows have been created."
#ifndef NDEBUG
"\nDebug info: Shellcode is \n"
I3WORKAROUND_SHELLCODE
#endif
)
;
options_description secondscreen("Options affecting the second screen");
secondscreen.add_options()
Expand Down Expand Up @@ -245,3 +264,13 @@ bool RuntimeConfiguration::filePathDefined() const
noFileNameException::noFileNameException():
logic_error("You did not specify a PDF-File to display.") {
}

bool RuntimeConfiguration::i3workaround() const
{
return m_i3workaround;
}

std::string RuntimeConfiguration::i3workaround_shellcode() const
{
return std::string( I3WORKAROUND_SHELLCODE );
}
16 changes: 16 additions & 0 deletions runtimeconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class RuntimeConfiguration
*/
bool m_useSecondScreen;

/** Workaround for i3 window manager active
*/
bool m_i3workaround;

/** Make sure that so many previous pages are pre-rendered
* (Probably wont make sense until you can jump to slide
* n without visiting 0..(n-1) first, but once PDF hyperlinks
Expand Down Expand Up @@ -121,6 +125,18 @@ class RuntimeConfiguration

unsigned bottomPaneHeight() const;
bool hyperlinkSupport() const;

/* Use i3-workaround.
*
* In the future, this might auto-detect if we're running on i3.
*/
bool i3workaround() const;

/* What shellcode to execute.
*
* This may be programatically generated in the future.
*/
std::string i3workaround_shellcode() const;
};

#endif // RUNTIMECONFIGURATION_H

0 comments on commit 5ab6424

Please sign in to comment.