Solved

Get window title in linux

Posted on 2007-11-21
4
2,076 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now