Skip to content

Commit

Permalink
Tracking clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
MadFishTheOne committed Apr 22, 2011
1 parent 1a24188 commit 44fb447
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
71 changes: 69 additions & 2 deletions dockapplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@

#include <stdio.h>

Client::Client(DockApplet* dockApplet, unsigned long handle)
{
m_dockApplet = dockApplet;
m_dockApplet->registerClient(this);
m_handle = handle;
m_name = X11Support::instance()->getWindowName(m_handle);

fprintf(stderr, "New client: %s\n", m_name.toUtf8().data());
}

Client::~Client()
{
m_dockApplet->unregisterClient(this);
}

void Client::removed()
{
fprintf(stderr, "Client removed: %s\n", m_name.toUtf8().data());

// Call destructor for now.
// TODO: Animations.
delete this;
}

DockApplet::DockApplet(PanelWindow* panelWindow)
: Applet(panelWindow)
{
Expand Down Expand Up @@ -35,12 +59,55 @@ QSize DockApplet::desiredSize()
return QSize(-1, -1); // Take all available space.
}

void DockApplet::registerClient(Client* client)
{
m_clients.append(client);
}

void DockApplet::unregisterClient(Client* client)
{
m_clients.remove(m_clients.indexOf(client));
}

void DockApplet::clientListChanged()
{
fprintf(stderr, "New client list:\n");
QVector<unsigned long> windows = X11Support::instance()->getWindowPropertyWindowsArray(X11Support::instance()->rootWindow(), "_NET_CLIENT_LIST");

// Handle new clients.
for(int i = 0; i < windows.size(); i++)
{
fprintf(stderr, "%s\n", X11Support::instance()->getWindowName(windows[i]).toUtf8().data());
bool found = false;
for(int k = 0; k < m_clients.size(); k++)
{
if(m_clients[k]->handle() == windows[i])
{
found = true;
break;
}
}

if(!found)
{
Client* client = new Client(this, windows[i]);
}
}

// Handle removed clients.
for(int i = 0; i < m_clients.size(); i++)
{
bool found = false;
for(int k = 0; k < windows.size(); k++)
{
if(m_clients[i]->handle() == windows[k])
{
found = true;
break;
}
}

if(!found)
{
m_clients[i]->removed();
}
}
}
30 changes: 30 additions & 0 deletions dockapplet.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
#ifndef DOCKAPPLET_H
#define DOCKAPPLET_H

#include <QtCore/QVector>
#include "applet.h"

class DockApplet;

class Client
{
public:
Client(DockApplet* dockApplet, unsigned long handle);
~Client();

unsigned long handle() const
{
return m_handle;
}

// Separate from destructor, as we would like to animate removal, so actual
// destruction will happen later.
void removed();

private:
DockApplet* m_dockApplet;
unsigned long m_handle;
QString m_name;
};

class DockApplet: public Applet
{
Q_OBJECT
Expand All @@ -13,11 +37,17 @@ class DockApplet: public Applet
bool init();
QSize desiredSize();

void registerClient(Client* client);
void unregisterClient(Client* client);

protected:
void layoutChanged();

private slots:
void clientListChanged();

private:
QVector<Client*> m_clients;
};

#endif
1 change: 0 additions & 1 deletion panelapplication.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "panelapplication.h"

#include <stdio.h>
#include <QtGui/QX11Info>
#include "x11support.h"

Expand Down

0 comments on commit 44fb447

Please sign in to comment.