Solved

Get window title in linux

Posted on 2007-11-21
4
2,090 Views
Last Modified: 2012-08-13
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
Comment
Question by:aczire
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:cup
ID: 20339347
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
 
LVL 1

Author Comment

by:aczire
ID: 20348599
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
 
LVL 11

Accepted Solution

by:
cup earned 50 total points
ID: 20352594
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
 
LVL 1

Author Closing Comment

by:aczire
ID: 31410342
I'll check it out and tell u.Thanks a lot
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question