lettier / movie-monad

:tv: A free and simple to use video player made with Haskell.
https://lettier.github.io/movie-monad
BSD 3-Clause "New" or "Revised" License
420 stars 24 forks source link

Disable screensaver when playing video #7

Closed AntouanK closed 6 years ago

AntouanK commented 6 years ago

I've noticed that other video players, like vlc, disable somehow the screensaver when playing a video. Can you do the same on movie-monad?

lettier commented 6 years ago

Hello @AntouanK.

Are you using Linux? If so, which screensaver are you using?

:+1:

AntouanK commented 6 years ago

I'm using Antergos, an Arch distro. To be honest, I didn't set up the screensaver at all. I think the default "power management" setup, is to make the monitor go to sleep in 10 minutes. I just noticed that on movies on vlc, I never had to disable it. It did it by itself somehow.

lettier commented 6 years ago

Hello @AntouanK

I have put in power management and screensaver disablement while the program runs.

:+1:

AntouanK commented 6 years ago

@lettier You're the man! I'll try it later today. Many thanks.

AntouanK commented 6 years ago

@lettier I git pulled, and then stack build. I got this at the end

...

    [1 of 2] Compiling Main             ( /tmp/stack13341/network-2.6.3.2/Setup.hs, /tmp/stack13341/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/Main.o )
    [2 of 2] Compiling StackSetupShim   ( /home/antouank/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack13341/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/StackSetupShim.o )
    Linking /tmp/stack13341/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/setup ...
    Configuring network-2.6.3.2...
    configure: WARNING: unrecognized options: --with-compiler
    checking build system type... x86_64-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking for gcc... /usr/bin/gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... configure: error: in `/tmp/stack13341/network-2.6.3.2':
    configure: error: cannot run C compiled programs.
    If you meant to cross compile, use `--host'.
    See `config.log' for more details

Does it make any sense? Do I have to ./configure or something?

lettier commented 6 years ago

Hello @AntouanK

What version of stack do you have?

I have verision 1.3.2.

Version 1.3.2, Git revision 3f675146590da4f3edf768b89355f798229da2a5 (4395 commits) x86_64 hpack-0.15.0

I tried with a fresh clone and ran the following.

stack setup
stack build

The compilation was successful.

Try removing the stack work directory.

cd movie-monad
rm -rf .stack-work/
stack clean
stack setup
stack build

Alternatively you can try the AppImage.

wget https://github.com/lettier/movie-monad/releases/download/0.0.2.0/movie-monad-0.0.2.0-x86_64.AppImage
chmod a+x movie-monad-0.0.2.0-x86_64.AppImage
./movie-monad-0.0.2.0-x86_64.AppImage

:+1:

AntouanK commented 6 years ago
$ stack --version
Version 1.6.0.20171022 x86_64

I tried stack setup && stack build, output was the same. Then I tried rm -rf .stack-work/ && stack clean && stack setup && stack build, output was the same. :/

lettier commented 6 years ago

Hello @AntouanK

I tried building Movie Monad on a fresh VM using Antergos. I was able to reproduce your findings.

After looking around I discovered this obscure fix.

Open the following file.

~/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/options

Edit the following (key, value) entries to look like the following.

("C compiler flags", "-fno-PIE -fno-stack-protector"),
("C compiler link flags", "-no-pie"),
("ld flags", "-no-pie"),

Once edited, you should be able to build Movie Monad.

Here is the complete file.

[("GCC extra via C opts", " -fwrapv -fno-builtin"),
 ("C compiler command", "/usr/bin/gcc"),
 ("C compiler flags", "-fno-PIE -fno-stack-protector"),
 ("C compiler link flags", "-no-pie"),
 ("C compiler supports -no-pie", "YES"),
 ("Haskell CPP command","/usr/bin/gcc"),
 ("Haskell CPP flags","-E -undef -traditional"),
 ("ld command", "/usr/bin/ld"),
 ("ld flags", "-no-pie"),
 ("ld supports compact unwind", "YES"),
 ("ld supports build-id", "YES"),
 ("ld supports filelist", "NO"),
 ("ld is GNU ld", "YES"),
 ("ar command", "/usr/bin/ar"),
 ("ar flags", "q"),
 ("ar supports at file", "YES"),
 ("touch command", "touch"),
 ("dllwrap command", "/bin/false"),
 ("windres command", "/bin/false"),
 ("libtool command", "libtool"),
 ("perl command", "/usr/bin/perl"),
 ("cross compiling", "NO"),
 ("target os", "OSLinux"),
 ("target arch", "ArchX86_64"),
 ("target word size", "8"),
 ("target has GNU nonexec stack", "True"),
 ("target has .ident directive", "True"),
 ("target has subsections via symbols", "False"),
 ("Unregisterised", "NO"),
 ("LLVM llc command", "llc"),
 ("LLVM opt command", "opt")

:+1:

AntouanK commented 6 years ago

Amazing work, thanks.

Instead of options I guess you meant settings? In any case, I made the change in the settings file ( I only had to change the "C compiler link flags" value ) Now I get an error in step 7

Building all executables for `movie-monad' once. After a successful build of all of them, only specified executables will be rebuilt.
movie-monad-0.0.2.0: configure (exe)
Configuring movie-monad-0.0.2.0...
movie-monad-0.0.2.0: build (exe)
Preprocessing executable 'movie-monad' for movie-monad-0.0.2.0...
[ 1 of 19] Compiling Utils            ( src/Utils.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/Utils.o )
[ 2 of 19] Compiling Uri              ( src/Uri.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/Uri.o )
[ 3 of 19] Compiling Records          ( src/Records.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/Records.o )
[ 4 of 19] Compiling ScreensaverAndPowerManagement ( src/ScreensaverAndPowerManagement.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/ScreensaverAndPowerManagement.o )
[ 5 of 19] Compiling Seek             ( src/Seek.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/Seek.o )
[ 6 of 19] Compiling VideoInfo        ( src/VideoInfo.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/VideoInfo.o )
[ 7 of 19] Compiling PlayPause        ( src/PlayPause.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/PlayPause.o )

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:64:41: error:
    • Couldn't match expected type ‘Maybe b1’
                  with actual type ‘GI.Gtk.Image’
    • In the second argument of ‘GI.Gtk.buttonSetImage’, namely
        ‘playImage’
      In a stmt of a 'do' block:
        GI.Gtk.buttonSetImage playPauseButton playImage
      In the expression:
        do { GI.Gtk.buttonSetImage playPauseButton playImage;
             GI.Gtk.widgetSetTooltipText
               playPauseButton (Just "Click to play") }

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:61:41: error:
    • Couldn't match expected type ‘Maybe b0’
                  with actual type ‘GI.Gtk.Image’
    • In the second argument of ‘GI.Gtk.buttonSetImage’, namely
        ‘pauseImage’
      In a stmt of a 'do' block:
        GI.Gtk.buttonSetImage playPauseButton pauseImage
      In the expression:
        do { GI.Gtk.buttonSetImage playPauseButton pauseImage;
             GI.Gtk.widgetSetTooltipText
               playPauseButton (Just "Click to pause") }
Completed 25 action(s).

--  While building package movie-monad-0.0.2.0 using:
      /home/antouank/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build exe:movie-monad --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
lettier commented 6 years ago

Hello @AntouanK

Yes I ran across this as well.

For earlier versions of GTK+ < 3.22.24, the GObject introspection file incorrectly describes a function's parameter. In 3.22.24 at least, this has been fixed but now breaks backwards compatibility.

I will have to open a PR with the bindings Movie Monad uses.

In the meantime, you can either

Note that you only have to do one of the following procedures.


To downgrade:

# Use https://archive.archlinux.org/packages/g/gtk3/gtk3-3.22.16-1-x86_64.pkg.tar.xz if you have 64bit
# Use https://archive.archlinux.org/packages/g/gtk3/gtk3-3.22.16-1-i686.pkg.tar.xz if you have 32bit
sudo pacman -U https://archive.archlinux.org/packages/g/gtk3/gtk3-3.22.16-1-x86_64.pkg.tar.xz
cd movie-monad
stack exec -- ghc-pkg unregister --force haskell-gi
stack clean
stack build

To edit the GIR file:

sudo cp /usr/share/gir-1.0/Gtk-3.0.gir /usr/share/gir-1.0/Gtk-3.0.gir.bkup
# Replace Vim with your preferred editor
sudo vim /usr/share/gir-1.0/Gtk-3.0.gir

Swap out lines 13930 to 13953

      <method name="set_image"
              c:identifier="gtk_button_set_image"
              version="2.6">
        <doc xml:space="preserve">Set the image of @button to the given widget. The image will be
displayed if the label text is %NULL or if
#GtkButton:always-show-image is %TRUE. You don’t have to call
gtk_widget_show() on @image yourself.</doc>
        <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
        </return-value>
        <parameters>
          <instance-parameter name="button" transfer-ownership="none">
            <doc xml:space="preserve">a #GtkButton</doc>
            <type name="Button" c:type="GtkButton*"/>
          </instance-parameter>
          <parameter name="image"
                     transfer-ownership="none"
                     nullable="1"
                     allow-none="1">
            <doc xml:space="preserve">a widget to set as the image for the button, or %NULL to unset</doc>
            <type name="Widget" c:type="GtkWidget*"/>
          </parameter>
        </parameters>
      </method>

with

      <method name="set_image"
              c:identifier="gtk_button_set_image"
              version="2.6">
        <doc xml:space="preserve">Set the image of @button to the given widget. The image will be
displayed if the label text is %NULL or if
#GtkButton:always-show-image is %TRUE. You don’t have to call
gtk_widget_show() on @image yourself.</doc>
        <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
        </return-value>
        <parameters>
          <instance-parameter name="button" transfer-ownership="none">
            <doc xml:space="preserve">a #GtkButton</doc>
            <type name="Button" c:type="GtkButton*"/>
          </instance-parameter>
          <parameter name="image" transfer-ownership="none">
            <doc xml:space="preserve">a widget to set as the image for the button</doc>
            <type name="Widget" c:type="GtkWidget*"/>
          </parameter>
        </parameters>
      </method>

and run

cd movie-monad
stack exec -- ghc-pkg unregister --force haskell-gi
stack clean
stack build

To modify Movie Monad's source:

cd movie-monad/
# Replace Vim with your preferred editor
vim src/PlayPause.hs

Edit line https://github.com/lettier/movie-monad/blob/master/src/PlayPause.hs#L47 to look like

      setPlayPauseButton playPauseButton playImage (Just pauseImage) False

and edit line https://github.com/lettier/movie-monad/blob/master/src/PlayPause.hs#L50 to look like

      setPlayPauseButton playPauseButton playImage (Just pauseImage) True

:+1:

AntouanK commented 6 years ago

In order to not break anything else that uses GTK, I'll change the 2 lines in the source code for now. So once it's fixed, I can just git pull the latest. Let me give it a try now and I'll let you know.

AntouanK commented 6 years ago

Hmm, that didn't work. Or I messed something up.

$ git diff

diff --git a/src/PlayPause.hs b/src/PlayPause.hs
index 5c164fd..705be92 100644
--- a/src/PlayPause.hs
+++ b/src/PlayPause.hs
@@ -44,10 +44,10 @@ playPauseButtonClickHandler
   isPlaying <- isPlayPauseButtonPlaying playPauseButton
   if isPlaying
     then do
-      setPlayPauseButton playPauseButton playImage pauseImage False
+      setPlayPauseButton playPauseButton playImage (Just pauseImage) False
       void $ GI.Gst.elementSetState playbin GI.Gst.StatePaused
     else do
-      setPlayPauseButton playPauseButton playImage pauseImage True
+      setPlayPauseButton playPauseButton playImage (Just pauseImage) True
       void $ GI.Gst.elementSetState playbin GI.Gst.StatePlaying
   return False
$ stack build
Building all executables for `movie-monad' once. After a successful build of all of them, only specified executables will be rebuilt.
movie-monad-0.0.2.0: build (exe)
Preprocessing executable 'movie-monad' for movie-monad-0.0.2.0...
[ 7 of 19] Compiling PlayPause        ( src/PlayPause.hs, .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/movie-monad/movie-monad-tmp/PlayPause.o )

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:64:41: error:
    • Couldn't match expected type ‘Maybe b1’
                  with actual type ‘GI.Gtk.Image’
    • In the second argument of ‘GI.Gtk.buttonSetImage’, namely
        ‘playImage’
      In a stmt of a 'do' block:
        GI.Gtk.buttonSetImage playPauseButton playImage
      In the expression:
        do { GI.Gtk.buttonSetImage playPauseButton playImage;
             GI.Gtk.widgetSetTooltipText
               playPauseButton (Just "Click to play") }

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:61:41: error:
    • Couldn't match expected type ‘Maybe b0’
                  with actual type ‘GI.Gtk.Image’
    • In the second argument of ‘GI.Gtk.buttonSetImage’, namely
        ‘pauseImage’
      In a stmt of a 'do' block:
        GI.Gtk.buttonSetImage playPauseButton pauseImage
      In the expression:
        do { GI.Gtk.buttonSetImage playPauseButton pauseImage;
             GI.Gtk.widgetSetTooltipText
               playPauseButton (Just "Click to pause") }

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:50:53: error:
    • Couldn't match expected type ‘GI.Gtk.Image’
                  with actual type ‘Maybe GI.Gtk.Image’
    • In the third argument of ‘setPlayPauseButton’, namely
        ‘(Just pauseImage)’
      In a stmt of a 'do' block:
        setPlayPauseButton playPauseButton playImage (Just pauseImage) True
      In the expression:
        do { setPlayPauseButton
               playPauseButton playImage (Just pauseImage) True;
             void $ GI.Gst.elementSetState playbin GI.Gst.StatePlaying }

/run/media/antouank/evo1/_REPOS_/movie-monad/src/PlayPause.hs:47:53: error:
    • Couldn't match expected type ‘GI.Gtk.Image’
                  with actual type ‘Maybe GI.Gtk.Image’
    • In the third argument of ‘setPlayPauseButton’, namely
        ‘(Just pauseImage)’
      In a stmt of a 'do' block:
        setPlayPauseButton
          playPauseButton playImage (Just pauseImage) False
      In the expression:
        do { setPlayPauseButton
               playPauseButton playImage (Just pauseImage) False;
             void $ GI.Gst.elementSetState playbin GI.Gst.StatePaused }

--  While building package movie-monad-0.0.2.0 using:
      /home/antouank/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build exe:movie-monad --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
lettier commented 6 years ago

Hello @AntouanK

I apologize. I had the wrong line numbers. The correct ones are 61 and 64.

Here are the correct changes.

diff --git a/src/PlayPause.hs b/src/PlayPause.hs
index 5c164fd..af59384 100644
--- a/src/PlayPause.hs
+++ b/src/PlayPause.hs
@@ -58,10 +58,10 @@ setPlayPauseButton ::
   Bool ->
   IO ()
 setPlayPauseButton playPauseButton _ pauseImage True = do
-  GI.Gtk.buttonSetImage playPauseButton pauseImage
+  GI.Gtk.buttonSetImage playPauseButton (Just pauseImage)
   GI.Gtk.widgetSetTooltipText playPauseButton (Just "Click to pause")
 setPlayPauseButton playPauseButton playImage _ False = do
-  GI.Gtk.buttonSetImage playPauseButton playImage
+  GI.Gtk.buttonSetImage playPauseButton (Just playImage)
   GI.Gtk.widgetSetTooltipText playPauseButton (Just "Click to play")

:+1:

AntouanK commented 6 years ago

No need to apologise, you gave me probably the best issue answer I've seen in github so far :) Detailed solutions for all cases :)

So, changed those lines, and all work perfectly. Build done. I'll try a long video or a movie later, to test the screensaver feature. And again, many thanks for this.