Merge branch 'maemo/beowulf'
This commit is contained in:
		
						commit
						189766f68e
					
				
					 6 changed files with 40 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -25,7 +25,7 @@ struct Config
 | 
			
		|||
    bool ignoreClientMachine = false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const char *argp_program_version = "1.0.1";
 | 
			
		||||
const char *argp_program_version = "1.0.4";
 | 
			
		||||
const char *argp_program_bug_address = "<carl@uvos.xyz>";
 | 
			
		||||
static char doc[] = "Deamon that stops programms via SIGSTOP when their X11 windows lose focus.";
 | 
			
		||||
static char args_doc[] = "";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								debian/changelog
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								debian/changelog
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,3 +1,11 @@
 | 
			
		|||
sigstoped (1:1.0.2-1) unstable; urgency=medium
 | 
			
		||||
sigstoped (1.0.4) unstable; urgency=medium
 | 
			
		||||
  Fix memory leak in XInstance::getTopLevelWindows()
 | 
			
		||||
 -- Uvos <carl@uvos.xyz>  Mon, 16 Jun 2020 09:47:00 +0100
 | 
			
		||||
 | 
			
		||||
sigstoped (1.0.3) unstable; urgency=medium
 | 
			
		||||
  Ignore BadWindow errors caused by faulty __NET_ACTIVE_WINDOW events
 | 
			
		||||
 -- Uvos <carl@uvos.xyz>  Mon, 15 Jun 2020 23:47:00 +0100
 | 
			
		||||
 | 
			
		||||
sigstoped (1.0.2) unstable; urgency=medium
 | 
			
		||||
  Inital version
 | 
			
		||||
 -- Uvos <carl@uvos.xyz>  Mon, 10 Jun 2020 15:00:00 +0100
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								debian/control
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/control
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -12,6 +12,6 @@ Package: sigstoped
 | 
			
		|||
Architecture: any
 | 
			
		||||
Multi-arch: same
 | 
			
		||||
Depends:
 | 
			
		||||
 libx11,
 | 
			
		||||
 libx11-6,
 | 
			
		||||
Description: A deamon that stops programms via SIGSTOP when their X11 windows lose focus.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								main.cpp
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								main.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -22,7 +22,6 @@
 | 
			
		|||
#include <cstdlib>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <X11/extensions/dpms.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +159,7 @@ int main(int argc, char* argv[])
 | 
			
		|||
    std::string confDir = getConfdir();
 | 
			
		||||
    if(confDir.size() == 0) return 1;
 | 
			
		||||
    
 | 
			
		||||
    if(!createPidFile(confDir+"pidfile"));
 | 
			
		||||
    if(!createPidFile(confDir+"pidfile")) return 1;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<std::string> applicationNames = getApplicationlist(confDir+"blacklist");
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -107,13 +107,13 @@ std::vector<Window> XInstance::getTopLevelWindows()
 | 
			
		|||
    Window* windows = nullptr;
 | 
			
		||||
    unsigned int nwindows;
 | 
			
		||||
    XQueryTree(display, RootWindow(display, screen), &root_return, &parent_return, &windows, &nwindows);
 | 
			
		||||
    
 | 
			
		||||
    std::vector<Window> out;
 | 
			
		||||
    out.reserve(nwindows);
 | 
			
		||||
    for(unsigned int i; i < nwindows; ++i)
 | 
			
		||||
    for(unsigned int i = 0; i < nwindows; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        out.push_back(windows[i]);
 | 
			
		||||
    }
 | 
			
		||||
    if(windows != nullptr) XFree(windows);
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -124,6 +124,7 @@ void XInstance::flush()
 | 
			
		|||
 | 
			
		||||
pid_t XInstance::getPid(Window wid)
 | 
			
		||||
{
 | 
			
		||||
    defaultHandler = XSetErrorHandler(ignoreErrorHandler);
 | 
			
		||||
    XTextProperty xWidHostNameTextProperty;
 | 
			
		||||
    bool ret;
 | 
			
		||||
    ret = XGetTextProperty(display, wid, &xWidHostNameTextProperty, atoms.wmClientMachine); 
 | 
			
		||||
| 
						 | 
				
			
			@ -132,7 +133,11 @@ pid_t XInstance::getPid(Window wid)
 | 
			
		|||
        char errorString[1024];
 | 
			
		||||
        XGetErrorText(display, ret, errorString, 1024);
 | 
			
		||||
        debug("XGetWMClientMachine failed! " + std::string(errorString));
 | 
			
		||||
        if(!ignoreClientMachine) return -1;
 | 
			
		||||
        if(!ignoreClientMachine) 
 | 
			
		||||
        {
 | 
			
		||||
            XSetErrorHandler(defaultHandler);
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    char** xWidHostNameStringList = nullptr;
 | 
			
		||||
    int nStrings;
 | 
			
		||||
| 
						 | 
				
			
			@ -142,13 +147,21 @@ pid_t XInstance::getPid(Window wid)
 | 
			
		|||
        char errorString[1024];
 | 
			
		||||
        XGetErrorText(display, ret, errorString, 1024);
 | 
			
		||||
        debug("XTextPropertyToStringList failed! " + std::string(errorString));
 | 
			
		||||
        if(!ignoreClientMachine) return -1;
 | 
			
		||||
        if(!ignoreClientMachine) 
 | 
			
		||||
        {
 | 
			
		||||
            XSetErrorHandler(defaultHandler);
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    char hostName[HOST_NAME_MAX+1]={0};
 | 
			
		||||
    if(gethostname(hostName, HOST_NAME_MAX) != 0)
 | 
			
		||||
    {
 | 
			
		||||
        debug("Can't get host name");
 | 
			
		||||
        if(!ignoreClientMachine) return -1;
 | 
			
		||||
        if(!ignoreClientMachine) 
 | 
			
		||||
        {
 | 
			
		||||
            XSetErrorHandler(defaultHandler);
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    pid_t pid = -1;
 | 
			
		||||
    if(ignoreClientMachine || strcmp(hostName, xWidHostNameStringList[0]) == 0 )
 | 
			
		||||
| 
						 | 
				
			
			@ -165,9 +178,17 @@ pid_t XInstance::getPid(Window wid)
 | 
			
		|||
        debug("Window "+std::to_string(wid)+" is a remote window");
 | 
			
		||||
    }
 | 
			
		||||
    if(xWidHostNameStringList) XFreeStringList(xWidHostNameStringList);
 | 
			
		||||
    XSetErrorHandler(defaultHandler);
 | 
			
		||||
    return pid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int XInstance::ignoreErrorHandler(Display* display, XErrorEvent* xerror)
 | 
			
		||||
{
 | 
			
		||||
    std::cerr<<"Ignoring: error code"<<xerror->error_code<<" request code "<<xerror->request_code<<'\n'
 | 
			
		||||
             <<"this error most likely occured because of a bug in your WM\n";
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 XInstance::~XInstance()
 | 
			
		||||
 {
 | 
			
		||||
     if(display) XCloseDisplay(display);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,6 +34,7 @@ class XInstance
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
    
 | 
			
		||||
    inline static XErrorHandler defaultHandler;
 | 
			
		||||
    static constexpr unsigned long MAX_BYTES = 1048576;
 | 
			
		||||
    
 | 
			
		||||
    inline static bool ignoreClientMachine = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,6 +47,7 @@ private:
 | 
			
		|||
    
 | 
			
		||||
    unsigned long readProparty(Window wid, Atom atom, unsigned char** prop, int* format);
 | 
			
		||||
    Atom getAtom(const std::string& atomName);
 | 
			
		||||
    static int ignoreErrorHandler(Display* display, XErrorEvent* xerror);
 | 
			
		||||
    
 | 
			
		||||
public:
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue