Difference between revisions of "Tutorials/C Programming Tutorial/How to find out desktop idle time"

From ThorstensHome
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:How to find out desktop idle time}}
 
I wrote this little program because I needed it to test the functionality my program ktimetracker is based on. It shows how long you did not do any user-input, waits 10 seconds, and shows again how long you did not do any user-input. I found it works perfect on SUSE Linux 10.3, and on SUSE Linux 11.1. There was a [https://bugs.kde.org/show_bug.cgi?id=169958 problem outlined here].
 
I wrote this little program because I needed it to test the functionality my program ktimetracker is based on. It shows how long you did not do any user-input, waits 10 seconds, and shows again how long you did not do any user-input. I found it works perfect on SUSE Linux 10.3, and on SUSE Linux 11.1. There was a [https://bugs.kde.org/show_bug.cgi?id=169958 problem outlined here].
 
<pre>
 
<pre>
Line 29: Line 30:
 
'''Kompile with'''  
 
'''Kompile with'''  
 
  qmake -project  
 
  qmake -project  
  qmake   
+
  [[qmake]]  
 
  make  
 
  make  
 
  g++ -m64 -o x11test main.o -L/usr/lib64 -lQtGui -L/usr/lib64 -L/usr/X11R6/lib64 -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -lrt -ldl -lpthread -lXss  
 
  g++ -m64 -o x11test main.o -L/usr/lib64 -lQtGui -L/usr/lib64 -L/usr/X11R6/lib64 -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -lrt -ldl -lpthread -lXss  
 
'''run with'''
 
'''run with'''
 
  ./x11test
 
  ./x11test

Latest revision as of 20:18, 19 August 2011

I wrote this little program because I needed it to test the functionality my program ktimetracker is based on. It shows how long you did not do any user-input, waits 10 seconds, and shows again how long you did not do any user-input. I found it works perfect on SUSE Linux 10.3, and on SUSE Linux 11.1. There was a problem outlined here.

#include <QApplication>
#include <QPushButton>
#include <QX11Info>
#include <X11/extensions/scrnsaver.h>
#include <iostream>

using namespace std;

int main(int argc, char ** argv)
{
  QApplication qa(argc,argv);
  QPushButton* qp=new QPushButton("hello world");
  qp->show();
  int event_base, error_base;
  XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base);
  XScreenSaverInfo* _mit_info = XScreenSaverAllocInfo();
  XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), _mit_info);
  cout << _mit_info->idle << endl;
  int test; 
  sleep(10);
  XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), _mit_info);
  cout << _mit_info->idle << endl;
  return qa.exec();
}

Kompile with

qmake -project 
qmake  
make 
g++ -m64 -o x11test main.o -L/usr/lib64 -lQtGui -L/usr/lib64 -L/usr/X11R6/lib64 -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -lrt -ldl -lpthread -lXss 

run with

./x11test