Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: Who can drop few lines of code?Send you beer!

  1. #11
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Who can drop few lines of code?Send you beer!

    bump

  2. #12
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Who can drop few lines of code?Send you beer!

    realzippy, does this command activate your screensaver?
    If it does, that might be a start toward a solution:

    Code:
    qdbus org.gnome.ScreenSaver / SetActive True

  3. #13
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Who can drop few lines of code?Send you beer!

    Quote Originally Posted by unutbu View Post
    realzippy, does this command activate your screensaver?
    If it does, that might be a start toward a solution:

    Code:
    qdbus org.gnome.ScreenSaver / SetActive True

    YES!It does.....

  4. #14
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Who can drop few lines of code?Send you beer!

    Wonderful. Now here's (maybe) the tricky part: What does this return
    Code:
    sleep 5; qdbus org.gnome.ScreenSaver / GetSessionIdleTime
    Also, after the screensaver is activated, you want any keypress to have the same effect as pressing Shift+F9, correct? What does pressing Shift+F9 do?

  5. #15
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Who can drop few lines of code?Send you beer!

    Quote Originally Posted by unutbu View Post
    Wonderful. Now here's (maybe) the tricky part: What does this return
    Code:
    sleep 5; qdbus org.gnome.ScreenSaver / GetSessionIdleTime
    Also, after the screensaver is activated, you want any keypress to have the same effect as pressing Shift+F9, correct? What does pressing Shift+F9 do?
    ..it returns: 0



    Shift+F9 starts/stops compiz rainplugin,which I wanted as screensaver:

    "Ok,need some code:

    that "presses Shift+F9" after given time of Mouse/Keyboard inactivity and interpreted any next keyboard/mouse input as Shift+F9"

  6. #16
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Who can drop few lines of code?Send you beer!

    ..it returns: 0
    This is a show-stopper... at least until we find a way to coax the computer into telling us how long the X session has been idle.

    PS. When you run
    Code:
    qdbus org.gnome.ScreenSaver / SetActive True
    does the rain plugin start, or is your screen saver something else?

  7. #17
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Who can drop few lines of code?Send you beer!

    Quote Originally Posted by unutbu View Post
    This is a show-stopper... at least until we find a way to coax the computer into telling us how long the X session has been idle.

    PS. When you run
    Code:
    qdbus org.gnome.ScreenSaver / SetActive True
    does the rain plugin start, or is your screen saver something else?

    Default Gnome screensaver starts.
    rain plugin needs shift+F9...
    ...sorry for delay,soccer....

  8. #18
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Who can drop few lines of code?Send you beer!

    realzippy, Since compiz seems to crash my machine, I haven't been able to test this completely.

    • First install the build-essential, libxss-dev and xdotool packages.
    • Then go to http://ubuntuforums.org/showpost.php...64&postcount=2
      and copy stroyan's C program to xidle.c

      Compile the program:
      Code:
      cc xidle.c -o xidle -lX11 -lXext -lXss
      This will create the executable "xidle".
    • Move the executable xidle to ~/bin, so the program will be in your PATH.
    • Check that it works by running
      Code:
      sleep 5; xidle
      You should get a number like
      Code:
      4.962000
      in response.
    • Now save this in ~/bin/idlerain.py

      PHP Code:
      #!/usr/bin/env python
      from subprocess import Popen,PIPE,STDOUT,call
      import os
      import time

      def get_idle_time
      ():
          
      proc=Popen('xidle'shell=Truestdout=PIPE, )
          return 
      float(proc.communicate()[0])

      is_raining=False
      sleep_seconds
      =1
      max_idle
      =20
      last_idle
      =0
      rain_start_time
      =time.time()
      while 
      True:
          
      idle=get_idle_time()
          if 
      is_raining:
              
      duration=time.time()-rain_start_time        
              
      if(is_raining and duration>1.5*sleep_seconds and
                
      idle<last_idle):
                  
      is_raining=False
                  os
      .system('xdotool key shift+F9')        
          else:
              if (
      last_idle<max_idle and max_idle<=idle):
                  
      is_raining=True
                  rain_start_time
      =time.time()
                  
      os.system('xdotool key shift+F9')
          
      last_idle=idle
          time
      .sleep(sleep_seconds
    • Make it executable:
      Code:
      chmod +x ~/bin/idlerain.py
    • For now, try running it from the terminal. If it works to your liking, it can be set to run automatically when you log in.

      Run it by typing:
      Code:
      idlerain.py
      Wait for 20 seconds. Then the rain should start. Press a key, and the rain should end.

      Press Ctrl-C to stop the idlerain.py program.
    Last edited by unutbu; September 1st, 2009 at 02:45 PM.

  9. #19
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Who can drop few lines of code?Send you beer!

    Move the executable xidle to ~/bin, so the program will be in your PATH

    Sorry for stupid question:
    Is it really ~/bin,not /bin?

    (do not have /bin folder in home directory.Should i create it?...if I move xidle to /bin instead of ~/bin,then sleep 5; xidle gives me a number like 4.962000,
    otherwise "command not found"...????)
    Last edited by realzippy; August 30th, 2009 at 02:18 PM.

  10. #20
    Join Date
    Mar 2008
    Beans
    4,715
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Who can drop few lines of code?Send you beer!

    No problem, realzippy.

    ~/bin is the same as /home/realzippy/bin (if your username is realzippy).
    /bin is the system's /bin directory. (I don't recommend putting it in there.)

    If you don't have a ~/bin directory, make one. Ubuntu is setup for you so that if you have a ~/bin directory, all executables are automatically "in your PATH". That means you can run them by name:
    Code:
    xidle
    instead of by full path:
    Code:
    /home/realzippy/bin/xidle
    It saves some typing.

    PS. If you make a ~/bin directory, close your gnome-terminal and re-open it so your PATH will be updated.
    Last edited by unutbu; August 30th, 2009 at 02:11 PM.

Page 2 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •