LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2010, 12:41 AM   #1
hamedhsn
Member
 
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Rep: Reputation: 0
How to read the state by using _NET_WM_STATE in xlib


hi..
i want to get the state of a particular window by using the _NET_WM_STATE atom.
i dont know how to use it with XGetProperty.
i googled it by i could not find a way.
any sample code would be useful,thanks..
 
Old 10-10-2010, 01:33 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Here is an example. You need to add some error checking, and it assumes that the property format is 32 bits.

Code:
Atom wmState = ::XInternAtom(pDisplay, "_NET_WM_STATE", True);
Atom type;
int format;
unsigned long nItem, bytesAfter;
unsigned char *properties = NULL;
::XGetWindowProperty(pDisplay, window, wmState, 0, LONG_MAX, False, AnyPropertyType, &type, &format, &nItem, &bytesAfter, &properties);
for (int iItem = 0; iItem < nItem; ++iItem)
	std::cout << "property=" << reinterpret_cast<unsigned long *>(properties)[iItem] << std::endl;
 
Old 10-13-2010, 12:48 AM   #3
hamedhsn
Member
 
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Original Poster
Rep: Reputation: 0
i change code in c but it gives me 0 or 2 item.all of them are null

Code:
Atom wmState = XInternAtom(display, "_NET_WM_STATE", True);
Atom type;
int format;
unsigned long nItem, bytesAfter;
unsigned char *properties = NULL;
XGetWindowProperty(display, window, wmState, 0, (~0L), False, AnyPropertyType, &type, &format, &nItem, &bytesAfter, &properties);
int iItem;
usleep(1000000);
//printf("itemmmmmm=%d\n",nItem);
for (iItem = 0; iItem < nItem; ++iItem)
	printf("property=%ld\n",(long*)(properties)[nItem]);
my main purpose is to find out whether my window is minimized or maximized or etc. ??
what is the current state of my window??
thanks

Last edited by hamedhsn; 10-13-2010 at 12:49 AM.
 
Old 10-13-2010, 03:24 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by hamedhsn View Post
i change code in c but it gives me 0 or 2 item.all of them are null
There are two errors in the printf line:
  1. You are using nItem as the index instead of iItem.
  2. The precedence of the array subscript is higher than the precedence of the cast, so it is doing the array lookup before the cast!
 
Old 10-14-2010, 02:27 AM   #5
hamedhsn
Member
 
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Original Poster
Rep: Reputation: 0
i correct the mistake but i 'v got nothing.
my main purpose is to find out whether my window is minimized or maximized or etc. ??
what is the current state of my window??
thanks
 
Old 10-14-2010, 07:32 AM   #6
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by hamedhsn View Post
i correct the mistake but i'v got nothing.
The printf line should read something like:
Code:
printf("%ld\n", ((long *)(properties))[iItem]);
Quote:
my main purpose is to find out whether my window is minimized or maximized or etc.
If the window is maximized, it will have the atoms _NET_WM_STATE_MAXIMIZED_VERT and _NET_WM_STATE_MAXIMIZED_HORZ in the _NET_WM_STATE property list; if the window is minimized, it will have the atom _NET_WM_STATE_HIDDEN in the list. Other states (eg open but not maximized) may have an empty _NET_WM_STATE property list.

Last edited by neonsignal; 10-14-2010 at 07:34 AM.
 
1 members found this post helpful.
Old 10-15-2010, 01:12 AM   #7
hamedhsn
Member
 
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by neonsignal View Post
If the window is maximized, it will have the atoms _NET_WM_STATE_MAXIMIZED_VERT and _NET_WM_STATE_MAXIMIZED_HORZ in the _NET_WM_STATE property list; if the window is minimized, it will have the atom _NET_WM_STATE_HIDDEN in the list. Other states (eg open but not maximized) may have an empty _NET_WM_STATE property list.
thanks for your help.

Last edited by hamedhsn; 10-15-2010 at 01:37 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set deadeyes Linux - Server 14 07-29-2009 04:30 AM
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified rajnivanza Linux - Software 1 03-13-2008 01:16 PM
Setting X _NET_WM_STATE (making a window full screen) from a python/qt environment? enigma_0Z Programming 0 10-15-2007 02:33 PM
LXer: State by state, Microsoft responds to creeping threat LXer Syndicated Linux News 0 05-01-2007 07:16 AM
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified eyalkz Programming 1 03-02-2004 08:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration