Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2116
  • Last Modified:

Get window title in linux

Hai all, i need to develop a program to get the title of the active window and if it contains some words that are not allowed in the lab session i need to close it.Thatz the question in a nutshell.
Now i'll explian it a little more.
I'm studying. In our lab, the systems are mainly used to do our c,c++,java programs and we're permitted to browse the web in off lab hours.But most of us do these two at the same time i,e browse the net in our lab hours.Now i'm assigned by our HOD  to develop a tool to avoid this.What i need is a program to check the active window title continuously and if it contains some word like "FireFox,Opera,Orkut etc" it will spawn a command box to enter the Auth no: from our lab admin and if it is correct then allow the person to continue else close that window.This is coz when we are dng our lab peoples from other departments will be using it for browsing.
Now you got the main idea.Now tell me how to get the active window title, close it and start automatically upon system startup using C++. we're using RedHat,Debian, fedora etc........

0
aczire
Asked:
aczire
  • 2
  • 2
1 Solution
 
cupCommented:
Which window manager are you using?  You can get the title but the API for each window manager is different, unless you use native-X.  You also have to make sure nobody plays with the X-windows resource file.  You can modify the resource file to disguise the title.  The app can pick the resource file from one of 13 places.
0
 
aczireAuthor Commented:
Hai,
we are using KDE.Now tell me how can i get the title of the active window and get a handle to close it if it confirms to the specifications.
0
 
cupCommented:
I don't know a lot about KDE.  All I know is that it is based on Trolltech Qt.  You could use editres to find out what the title is called in the widget tree and then use XtVaGetValues to get the titles.

Build a simple app.  Add editres to the app

#include <X11/Xmu/Editres.h>

After you've created the app

XtAddEventHandler (shell, (EventMask)0, True, _XEditResCheckMessages, NULL);

where shell is the Application shell widget.  When you link, link with -lXmu

Start up your app and then run editres.  This is a pretty ancient program from the time of athena widgets.  The cursor is the box in the top left corner.  It is the window on a very large canvas.    From the Command menu, GetWidgetTree.   Select your app and you will get the widget tree of your app.  Expand the nodes until you find the title.  It will be something like label, toplabel or even title.  You can get editres to flash the widget you've selected to make sure you've got the right one.  

Once you've got the right one, show the resource box from the commands menu.  That will give you a brief idea of how to get to the title starting from the app widget.

You may need to start at the window manager, ask it for all its children and go through in turn getting the titles and the pids.

To close it, find out the pid and send it a kill -9.

Sorry - I cannot tell you any more than that.  I'm using Motif/CDE which is completely different from Qt/KDE.
0
 
aczireAuthor Commented:
I'll check it out and tell u.Thanks a lot
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now