findwindow를 구현하고 있는데요

kisungcho의 이미지

X상의 윈도우리스트를 뒤져서 그 창을 활성화 하려고 합니다.
꼭 그래야만 하는 이유가 있어서요.
그래서 window는 찾았는데 어떻게 그 창을 전면으로 내보내서 활성화 해야 할지 모르겠습니다.
조언 부탁드립니다. X에 떠있는 윈도우중 postmessage처럼 메시지를 보내던지 windowid를 어떻게 해서든지 원하는 것을 활성화 하고 싶습니다. XMapWindow단순하게 해서는 안되더라구요.

즐프되시고요


#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>


typedef struct 
{
   int Screen;                 // Screen Number;
   int ScreenWidth;            // Screen Width;
   int ScreenHeight;           // Height;
   Window RootWindow;          // Root Window i.e. Parent Window.
   unsigned long white_pixel;  //ID's of the black and white colors of screen.
   unsigned long black_pixel;  
} DP;

typedef struct
{
   Window root_return;
   Window parent_return;
   Window *children_return;
   unsigned int nchildren_return;
} TreeReturn;


#define FALSE 0
#define TRUE 1

#define DEBUG FALSE

#define EVENT_MASK SubstructureNotifyMask | PropertyChangeMask |KeyPressMask | KeyReleaseMask

int DigWindow(Window, int);
int BuildWindowListQ(int);
int ErrorHandler(Display*, XErrorEvent*);



#include "findwindow.h"

Display *display;           //X display pointer. We have to open a display to
//communication to the X server.
TreeReturn QTR;             //information from XQueryTree



int main(int argc, char *argv[])
{
	char *DEnv = NULL;          //target pointer for env variable.
	DP DisProp;                 //Display properties structure.
	int retCode = 0, i = 0, runType = 0, done = 0;
	char *syscall = NULL;
	
	struct timespec delay;
	delay.tv_sec = 1;
	delay.tv_nsec = 0;
	
	DEnv = getenv("DISPLAY");   // get display?
	runType = 0;

	if (DEnv == NULL)           // did we get the var?
      return 1;
	else
	{
		display = XOpenDisplay(DEnv);   //open the connection to the display.
		if (display == NULL)
		{
			printf("Cannot connect to X server %s\n", DEnv);
			return 1;
		}
		XSetErrorHandler(ErrorHandler);
	}

	DisProp.Screen = DefaultScreen(display);
	DisProp.ScreenWidth = DisplayWidth(display, DisProp.Screen);
	DisProp.ScreenHeight = DisplayHeight(display, DisProp.Screen);
	DisProp.RootWindow = RootWindow(display, DisProp.Screen);

	DisProp.white_pixel = WhitePixel(display, DisProp.Screen);
	DisProp.black_pixel = BlackPixel(display, DisProp.Screen);

	BuildWindowListQ(TRUE);   //populates WinQ and QTR struct, MUST BE CALLED 
                             // FALSE - AllowDuplicate = NO. TRUE - YES.
	if (NULL != QTR.children_return)
		XFree(QTR.children_return);
   
	XCloseDisplay(display);        //close the display. (previously opened)
	return 0;
}

int BuildWindowListQ(int dupWin)
{
   int retCode = 0, i = 0;

   retCode = XQueryTree(display, DefaultRootWindow(display), &QTR.root_return,
                        &QTR.parent_return, &QTR.children_return, 
                        &QTR.nchildren_return);

   XSelectInput(display, QTR.root_return, EVENT_MASK);

   if (retCode)
   {
      for (i = 0; i < QTR.nchildren_return; i++)
      {
	 if (!DigWindow(QTR.children_return[i], dupWin))
	    printf("API 0L Error");
      }//for
   }
   else
      return 0;
}

int DigWindow(Window target, int allowDupWin)
{
   int retCode, parentRetCode, i;
   char *text_name;
   XWindowAttributes window_attributes_return;

   Window root_return;
   Window parent_return;
   Window *children_return;
   unsigned int nchildren_return;

   parentRetCode = 1; 

   retCode = XQueryTree(display, target, &root_return,
			&parent_return, &children_return, 
			&nchildren_return);

   if (!retCode)
      return 1;
   
	retCode=XGetWindowAttributes(display, target, &window_attributes_return);
      
	if (retCode != 0)
	{
		if ((window_attributes_return.map_state == IsViewable) && (window_attributes_return.class == InputOutput))
		{
			retCode=XFetchName(display, target, &text_name);
	 
			if (retCode != 0)
			{
				printf("###Founded Window Name:%s\n", text_name);
            	XFree(text_name);
			}
		}
	}

   if (nchildren_return == 0)  {
      return 1;
   }  else   {
		XSelectInput(display, target, EVENT_MASK);

		for (i = 0; i < nchildren_return; i++)
		{
			if (!DigWindow(children_return[i], allowDupWin))
				parentRetCode = 0;
		}
      
		if (NULL != children_return)
			XFree(children_return);
   }

	return parentRetCode; 
}

int ErrorHandler(Display *display, XErrorEvent *error)
{
   if ((error->request_code == X_GetWindowAttributes) ||
       (error->request_code == X_ChangeWindowAttributes) ||
       (error->request_code == X_QueryTree) ||
       (error->request_code == X_GetProperty) ||
       (error->request_code == X_GetGeometry) &&
       (error->error_code == BadWindow) ||
       (error->error_code == BadDrawable)) {
          return 0;      
   }
   else
   {
      char *report = NULL;
      char num[10];
      report = malloc(100);
      memset(report, 0, 100);

      XGetErrorText(display, error->error_code, report, 100);
      printf("Xlib Error: <%s>\n", report);
      sprintf(num, "%i", error->request_code);
      XGetErrorDatabaseText(display, "XRequest", num, num, report, 100);
      printf("Request: %s <XID(%06x), Serial(%d/%d) Minor(%d)>\n\n",
	      report, error->resourceid, error->serial, 
	      LastKnownRequestProcessed(display), error->minor_code);

      exit(1);
   }
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.