From f5dd8fe760c32ee6526ad8c299a773d188d3ec87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Wed, 11 Jul 2012 03:36:42 +0200 Subject: [PATCH] Changed screen saver control to use fake events This closes Bug 1031 (cherry picked from commit 8fe6f08227059c8cddc686888fb3e402b83c9eff) --- config.h.in | 3 +++ configure.in | 29 ++++++++++++++++++++++++++ configure.in.in | 28 +++++++++++++++++++++++++ src/Makefile.am | 6 +++--- src/kmplayer.h | 6 ++++++ src/kmplayerapp.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ src/kmplayerpartbase.cpp | 5 +++++ src/kmplayerpartbase.h | 1 + src/kmplayerview.cpp | 15 -------------- src/kmplayerview.h | 1 - src/main.cpp | 1 + 11 files changed, 121 insertions(+), 19 deletions(-) diff --git a/config.h.in b/config.h.in index e3687cd..874e18e 100644 --- a/config.h.in +++ b/config.h.in @@ -105,6 +105,9 @@ /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF +/* XTest extension available */ +#undef HAVE_XTEST + /* If we have libxine installed */ #undef HAVE_XINE diff --git a/configure.in b/configure.in index 59ce251..c84cb7c 100644 --- a/configure.in +++ b/configure.in @@ -123,6 +123,35 @@ if test x$have_expat = xyes -a x$want_expat = xyes; then AC_SUBST(LIB_EXPAT) fi +dnl ------------------------- +dnl check for XTest extension +dnl ------------------------- + +AC_ARG_WITH([xtest], [AS_HELP_STRING([--without-xtest], [build without XTest support])],, + [with_xtest=yes]) + +CFLAGS_XTEST="" +LIB_XTEST="" + +if test "$with_xtest" != "no" ; then + AC_MSG_CHECKING([for XTest extension]) + + if "$PKG_CONFIG" --exists xtst ; then + with_xtest=yes + CFLAGS_XTEST=`"$PKG_CONFIG" --cflags xtst` + LIB_XTEST=`"$PKG_CONFIG" --libs xtst` + AC_DEFINE([HAVE_XTEST],,[XTest extension available]) + AC_MSG_RESULT([yes]) + else + with_xtest=no + AC_MSG_RESULT([no]) + fi +fi + +AC_SUBST([CFLAGS_XTEST]) +AC_SUBST([LIB_XTEST]) + + KDE_CHECK_HEADER(xine.h, have_xine=yes, have_xine=no) diff --git a/configure.in.in b/configure.in.in index 49b9228..bed41ce 100644 --- a/configure.in.in +++ b/configure.in.in @@ -58,6 +58,34 @@ if test x$have_expat = xyes -a x$want_expat = xyes; then AC_SUBST(LIB_EXPAT) fi +dnl ------------------------- +dnl check for XTest extension +dnl ------------------------- + +AC_ARG_WITH([xtest], [AS_HELP_STRING([--without-xtest], [build without XTest support])],, + [with_xtest=yes]) + +CFLAGS_XTEST="" +LIB_XTEST="" + +if test "$with_xtest" != "no" ; then + AC_MSG_CHECKING([for XTest extension]) + + if "$PKG_CONFIG" --exists xtst ; then + with_xtest=yes + CFLAGS_XTEST=`"$PKG_CONFIG" --cflags xtst` + LIB_XTEST=`"$PKG_CONFIG" --libs xtst` + AC_DEFINE([HAVE_XTEST],,[XTest extension available]) + AC_MSG_RESULT([yes]) + else + with_xtest=no + AC_MSG_RESULT([no]) + fi +fi + +AC_SUBST([CFLAGS_XTEST]) +AC_SUBST([LIB_XTEST]) + KDE_CHECK_HEADER(xine.h, have_xine=yes, have_xine=no) diff --git a/src/Makefile.am b/src/Makefile.am index 37a1d99..4ce9a9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,8 +5,8 @@ METASOURCES= AUTO lib_LTLIBRARIES= libkmplayercommon.la libkmplayercommon_la_SOURCES = viewarea.cpp kmplayerview.cpp playlistview.cpp kmplayercontrolpanel.cpp kmplayerconfig.cpp pref.cpp kmplayerprocess.cpp kmplayer_callback.skel kmplayer_backend.stub kmplayerpartbase.cpp kmplayerplaylist.cpp kmplayer_asx.cpp kmplayer_smil.cpp kmplayer_rp.cpp kmplayer_rss.cpp kmplayer_atom.cpp kmplayer_xspf.cpp triestring.cpp kmplayerpartbase.skel -libkmplayercommon_la_LDFLAGS = -avoid-version $(all_libraries) -libkmplayercommon_la_LIBADD = -lkmediaplayer $(LIB_KPARTS) $(LIB_KUTILS) $(LIB_EXPAT) -lm $(LIBCAIRO_LIBS) $(LIBQTDBUS) +libkmplayercommon_la_LDFLAGS = -avoid-version $(all_libraries) $(CFLAGS_XTEST) +libkmplayercommon_la_LIBADD = -lkmediaplayer $(LIB_KPARTS) $(LIB_KUTILS) $(LIB_EXPAT) -lm $(LIBCAIRO_LIBS) $(LIBQTDBUS) $(LIB_XTEST) if include_koffice_support kofficeplugin_lib= libkmplayerkofficepart.la @@ -25,7 +25,7 @@ libkmplayerkofficepart_la_LIBADD= libkmplayercommon.la $(LIB_KOFFICE) kdeinit_LTLIBRARIES=kmplayer.la kmplayer_la_SOURCES= main.cpp kmplayerapp.cpp kmplayertvsource.cpp kmplayerbroadcast.cpp kmplayervdr.cpp -kmplayer_la_LIBADD= libkmplayercommon.la +kmplayer_la_LIBADD= libkmplayercommon.la $(LIB_XTEST) kmplayer_la_LDFLAGS= -module $(KDE_PLUGIN) $(LIB_QT) EXTRA_PROGRAMS = kxineplayer kxvplayer kgstplayer diff --git a/src/kmplayer.h b/src/kmplayer.h index d513515..342fabc 100644 --- a/src/kmplayer.h +++ b/src/kmplayer.h @@ -137,6 +137,7 @@ private slots: void menuMoveUpNode (); void menuMoveDownNode (); void preparePlaylistMenu (KMPlayer::PlayListItem *, TQPopupMenu *); + void slotFakeKeyEvent(); private: void menuItemClicked (TQPopupMenu * menu, int id); @@ -192,6 +193,11 @@ private: bool m_played_exit; bool m_minimal_mode; bool m_auto_resize; + + TQTimer m_screensaverTimer; + bool m_haveKWin; + bool haveXTest; + int fakeKeycode; }; class KMPLAYER_NO_EXPORT FileDocument : public KMPlayer::Document { diff --git a/src/kmplayerapp.cpp b/src/kmplayerapp.cpp index eeee526..5c7e5d1 100644 --- a/src/kmplayerapp.cpp +++ b/src/kmplayerapp.cpp @@ -73,6 +73,12 @@ #include "kmplayervdr.h" #include "kmplayerconfig.h" +#include +#ifdef HAVE_XTEST +#include +#include +#endif + static const int DVDNav_start = 1; static const int DVDNav_previous = 2; static const int DVDNav_next = 3; @@ -533,6 +539,24 @@ KDE_NO_CDTOR_EXPORT KMPlayerApp::KMPlayerApp(TQWidget* , const char* name) initActions(); initView(); + haveXTest = false; +#ifdef HAVE_XTEST + int dummy_event, dummy_error, dummy_major, dummy_minor; + if (XTestQueryExtension(x11Display(), &dummy_event, &dummy_error, &dummy_major, &dummy_minor)) { + fakeKeycode = XKeysymToKeycode(x11Display(), XK_Shift_L); + if (fakeKeycode != 0) + haveXTest = true; + } +#endif + /** KWin are you there? **/ + m_haveKWin = KApplication::dcopClient()->isApplicationRegistered("kwin"); + if (m_haveKWin) + kdDebug() << "Window manager: KWin found" << endl; + else + kdDebug() << "Window manager: not KWin - using save fullscreen mode" << endl; + connect(&m_screensaverTimer, TQT_SIGNAL(timeout()), TQT_TQOBJECT(this), TQT_SLOT(slotFakeKeyEvent())); + m_screensaverTimer.start( 55000 ); + //setAutoSaveSettings(); playlist = new Playlist (this, lstsrc); playlist_id = m_view->playList ()->addTree (playlist, "listssource", "player_playlist", KMPlayer::PlayListView::AllowDrag | KMPlayer::PlayListView::AllowDrops | KMPlayer::PlayListView::TreeEdit | KMPlayer::PlayListView::Moveable | KMPlayer::PlayListView::Deleteable); @@ -685,6 +709,27 @@ KDE_NO_EXPORT void KMPlayerApp::initView () { setAcceptDrops (true); } +void KMPlayerApp::slotFakeKeyEvent() +{ + if ( m_player && m_player->isPlaying() && !m_player->isPaused()) + if (m_haveKWin) { + // use a better method if we're in a kde environment + kdDebug() << "KMPlayer: Fake mouse movement\n"; + XWarpPointer(x11Display(), None, None, 0, 0, 0, 0, 0, 0); + XFlush(x11Display()); + } else { + if(haveXTest) { +#ifdef HAVE_XTEST + kdDebug() << "KMPlayer: Fake key press\n"; + XTestFakeKeyEvent(x11Display(), fakeKeycode, true, 0); + XTestFakeKeyEvent(x11Display(), fakeKeycode, false, 0); + XFlush(x11Display()); +#endif + } + } +} + + KDE_NO_EXPORT void KMPlayerApp::loadingProgress (int perc) { if (perc < 100) statusBar ()->changeItem (TQString ("%1%").arg (perc), id_status_timer); diff --git a/src/kmplayerpartbase.cpp b/src/kmplayerpartbase.cpp index 6a6f84c..32ead14 100644 --- a/src/kmplayerpartbase.cpp +++ b/src/kmplayerpartbase.cpp @@ -874,6 +874,11 @@ KDE_NO_EXPORT bool PartBase::isPlaying () { return playing (); } +KDE_NO_EXPORT bool PartBase::isPaused () { + NodePtr doc = m_source ? m_source->document () : 0L; + return doc && doc->state == Node::state_deferred; +} + KAboutData* PartBase::createAboutData () { KMessageBox::error(0L, "createAboutData", "KMPlayer"); return 0; diff --git a/src/kmplayerpartbase.h b/src/kmplayerpartbase.h index 2ab8450..3fecb50 100644 --- a/src/kmplayerpartbase.h +++ b/src/kmplayerpartbase.h @@ -192,6 +192,7 @@ public: k_dcop: void toggleFullScreen (); bool isPlaying (); + bool isPaused (); signals: void sourceChanged (KMPlayer::Source * old, KMPlayer::Source * nw); void sourceDimensionChanged (); diff --git a/src/kmplayerview.cpp b/src/kmplayerview.cpp index 512a62d..c68fd43 100644 --- a/src/kmplayerview.cpp +++ b/src/kmplayerview.cpp @@ -599,27 +599,12 @@ bool View::isFullScreen () const { void View::fullScreen () { if (!m_view_area->isFullScreen()) { - m_sreensaver_disabled = false; - TQByteArray data, replydata; - TQCString replyType; - if (kapp->dcopClient ()->call ("kdesktop", "KScreensaverIface", - "isEnabled()", data, replyType, replydata)) { - bool enabled; - TQDataStream replystream (replydata, IO_ReadOnly); - replystream >> enabled; - if (enabled) - m_sreensaver_disabled = kapp->dcopClient()->send - ("kdesktop", "KScreensaverIface", "enable(bool)", TQString("false")); - } //if (m_keepsizeratio && m_viewer->aspect () < 0.01) // m_viewer->setAspect (1.0 * m_viewer->width() / m_viewer->height()); m_view_area->fullScreen(); m_control_panel->popupMenu ()->setItemVisible (ControlPanel::menu_zoom, false); m_widgetstack->visibleWidget ()->setFocus (); } else { - if (m_sreensaver_disabled) - m_sreensaver_disabled = !kapp->dcopClient()->send - ("kdesktop", "KScreensaverIface", "enable(bool)", TQString("true")); m_view_area->fullScreen(); m_control_panel->popupMenu ()->setItemVisible (ControlPanel::menu_zoom, true); } diff --git a/src/kmplayerview.h b/src/kmplayerview.h index 696ad48..dc6e20b 100644 --- a/src/kmplayerview.h +++ b/src/kmplayerview.h @@ -198,7 +198,6 @@ private: bool m_playing; bool m_mixer_init; bool m_inVolumeUpdate; - bool m_sreensaver_disabled; bool m_tmplog_needs_eol; bool m_revert_fullscreen; bool m_no_info; diff --git a/src/main.cpp b/src/main.cpp index 3cf6a1d..03874e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ email : #include #include +#include #include "kmplayer.h"