All pastes #492437 Raw Edit

_alexey_

public c v1 · immutable
·published 2007-05-17 05:24 UTC
rendered paste body
#include "xneur-ng.h"#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <unistd.h>#include <signal.h>#include <errno.h>static	Ecore_Timer *check;int main(int argc, char *argv[]){	printf("Program started\n");	if (!xneur_start())	{		return (-1);	}}static int xneur_start(){	// check if we`ve got another instance for current DISPLAY		Ecore_Event_Handler *h;	printf("Getting pid\n");	int pid = xnconfig_get_pid();	printf("Got pid %d\n",pid);	if (pid == -1){		return -1;	}	else if (pid){		if (kill(pid, SIGUSR1) == -1 && errno == ESRCH)		{					}		else		{			printf("Sorry you`ve already has xneur instance for current DISPLAY. Aborting\n");		 	return -1;		}			}	xnconfig_set_pid(getpid());	/*xneur_init();	 */ 	if (!ecore_init())	{		printf("xneur cannot Initialize Ecore!\n"			   "Perhaps you are out of memory?");		return -1;	}		/* setup a handler for when xneur is asked to exit via a system signal */   if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _xneur_signal_exit, NULL))     {		printf("xneur cannot set up an exit signal handler.\n"			       "Perhaps you are out of memory?");		ecore_shutdown();	       		//xneur_shutdown();     }     if (!ecore_x_init(NULL))     {		printf("Enlightenment cannot initialize its X connection.\n"			   "Have you set your DISPLAY variable?");		ecore_shutdown();     }          h = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, _xneur_x_cb_window_focus_out, NULL);          if (h)   	 {   	 	printf("ECORE_X_EVENT_WINDOW_FOCUS_OUT event has its handler\n");   	 }   	 h = ecore_event_handler_add(ECORE_X_EVENT_MASK_KEY_DOWN, _xneur_x_cb_window_key_down, NULL);     if (h)   	 {   	 	printf("ECORE_X_EVENT_MASK_KEY_DOWN event has its handler\n");   	 }   	 h = ecore_event_handler_add(ECORE_X_EVENT_MASK_KEY_UP, _xneur_x_cb_window_key_up, NULL);     if (h)   	 {   	 	printf("ECORE_X_EVENT_MASK_KEY_UP event has its handler\n");   	 }   	 check = ecore_timer_add (0.2, _xneur_x_cb_window_focus_get, NULL);     ecore_main_loop_begin();     if (check)     ecore_timer_del(check);	 ecore_x_shutdown();     ecore_shutdown();	/* no longer starting up */      /* start our main loop */   /*ecore_main_loop_begin();*/   return 1;   		}static int_xneur_signal_exit(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__){	printf("Caught either SIGINT SIGTERM or SIGQUIT signals\n"			"Quiting...........\n");	ecore_main_loop_quit();    return 1;}static int_xneur_x_cb_window_focus_out(void *data, int ev_type __UNUSED__, void *ev){   Ecore_X_Event_Window_Focus_Out *e;   e = ev;   printf("WINDOW %d\n",e->win);   if (_xneur_x_cb_window_focus_get(NULL))   check = ecore_timer_add (0.2, _xneur_x_cb_window_focus_get, NULL);   return 1;}static int_xneur_x_cb_window_focus_get(void *data){	char *n=NULL;	char *c=NULL;	Ecore_X_Window w = 0;	Ecore_X_Event_Mask m = (ECORE_X_EVENT_MASK_WINDOW_FOCUS_CHANGE | ECORE_X_EVENT_MASK_KEY_DOWN | ECORE_X_EVENT_MASK_KEY_DOWN);	w = ecore_x_window_focus_get();        ecore_x_event_mask_set(w,m);    if (w!=ecore_x_window_focus_get())    {    	printf("w!=ecore_x_window_focus_get()\n");    	ecore_x_event_mask_unset(w,m);    	return 1;    }    else    {    	ecore_x_icccm_name_class_get(w,&n,&c);					    	printf("Name:%s Class:%s\n",n,c);    	free(n);    	free(c);    	check = NULL;    	return 0;    }	}static int_xneur_x_cb_window_key_up(void *data, int ev_type __UNUSED__, void *ev){	printf("Recieved key up event\n");	return 1;}static int_xneur_x_cb_window_key_down(void *data, int ev_type __UNUSED__, void *ev){	printf("Recieved key down event\n");	return 1;}