~didrocks/unity/launcher-bug-fix-fest

« back to all changes in this revision

Viewing changes to src/BamfLauncherIcon.cpp

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Nux/Nux.h"
 
2
#include "Nux/BaseWindow.h"
 
3
 
 
4
#include "BamfLauncherIcon.h"
 
5
#include "Launcher.h"
 
6
#include "PluginAdapter.h"
 
7
 
 
8
#include <gio/gdesktopappinfo.h>
 
9
 
 
10
BamfLauncherIcon::BamfLauncherIcon (Launcher* IconManager, BamfApplication *app, CompScreen *screen, NUX_FILE_LINE_DECL)
 
11
:   SimpleLauncherIcon(IconManager)
 
12
{
 
13
    m_App = app;
 
14
    m_Screen = screen;
 
15
    char *icon_name = bamf_view_get_icon (BAMF_VIEW (m_App));
 
16
 
 
17
    SetTooltipText (bamf_view_get_name (BAMF_VIEW (app)));
 
18
    SetIconName (icon_name);
 
19
    
 
20
    if (bamf_view_is_sticky (BAMF_VIEW (m_App)))
 
21
      SetVisible (true);
 
22
    else
 
23
      SetVisible (bamf_view_user_visible (BAMF_VIEW (m_App)));
 
24
    
 
25
    SetActive (bamf_view_is_active (BAMF_VIEW (m_App)));
 
26
    SetRunning (bamf_view_is_running (BAMF_VIEW (m_App)));
 
27
    
 
28
    g_free (icon_name);
 
29
    
 
30
    g_signal_connect (app, "running-changed", (GCallback) &BamfLauncherIcon::OnRunningChanged, this);
 
31
    g_signal_connect (app, "active-changed", (GCallback) &BamfLauncherIcon::OnActiveChanged, this);
 
32
    g_signal_connect (app, "user-visible-changed", (GCallback) &BamfLauncherIcon::OnUserVisibleChanged, this);
 
33
    g_signal_connect (app, "closed", (GCallback) &BamfLauncherIcon::OnClosed, this);
 
34
}
 
35
 
 
36
BamfLauncherIcon::~BamfLauncherIcon()
 
37
{
 
38
}
 
39
 
 
40
void
 
41
BamfLauncherIcon::OnMouseClick ()
 
42
{
 
43
    BamfView *view;
 
44
    GList *children, *l;
 
45
    bool active, running;
 
46
    GDesktopAppInfo *appInfo;
 
47
    
 
48
    children = bamf_view_get_children (BAMF_VIEW (m_App));
 
49
    active = bamf_view_is_active (BAMF_VIEW (m_App));
 
50
    running = bamf_view_is_running (BAMF_VIEW (m_App));
 
51
    
 
52
    if (!running)
 
53
    {
 
54
      appInfo = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (BAMF_APPLICATION (m_App)));
 
55
      g_app_info_launch (G_APP_INFO (appInfo), NULL, NULL, NULL);
 
56
      g_object_unref (appInfo);
 
57
      return;
 
58
    }
 
59
    
 
60
    if (active)
 
61
    {
 
62
        std::list<Window> windowList;
 
63
        for (l = children; l; l = l->next)
 
64
        {
 
65
            view = (BamfView *) l->data;
 
66
        
 
67
            if (BAMF_IS_WINDOW (view))
 
68
            {
 
69
                guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
 
70
                
 
71
                windowList.push_back ((Window) xid);
 
72
            }
 
73
        }
 
74
        
 
75
        if (windowList.size () > 1)
 
76
        {
 
77
            std::string *match = PluginAdapter::Default ()->MatchStringForXids (&windowList);
 
78
            PluginAdapter::Default ()->InitiateScale (match);
 
79
            delete match;
 
80
        }
 
81
    }
 
82
    else
 
83
    {
 
84
        for (l = children; l; l = l->next)
 
85
        {
 
86
            view = (BamfView *) l->data;
 
87
        
 
88
            if (BAMF_IS_WINDOW (view))
 
89
            {
 
90
                guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
 
91
            
 
92
                CompWindow *window = m_Screen->findWindow ((Window) xid);
 
93
            
 
94
                if (window)
 
95
                  window->activate ();
 
96
            }
 
97
        }
 
98
    }
 
99
}
 
100
 
 
101
void
 
102
BamfLauncherIcon::OnClosed (BamfView *view, gpointer data)
 
103
{
 
104
    BamfLauncherIcon *self = (BamfLauncherIcon *) data;
 
105
    
 
106
    if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
 
107
      self->Remove ();
 
108
}
 
109
 
 
110
void
 
111
BamfLauncherIcon::OnUserVisibleChanged (BamfView *view, gboolean visible, gpointer data)
 
112
{
 
113
    BamfLauncherIcon *self = (BamfLauncherIcon *) data;
 
114
    
 
115
    if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
 
116
      self->SetVisible (visible);
 
117
}
 
118
 
 
119
void
 
120
BamfLauncherIcon::OnRunningChanged (BamfView *view, gboolean running, gpointer data)
 
121
{
 
122
    BamfLauncherIcon *self = (BamfLauncherIcon *) data;
 
123
    self->SetRunning (running);
 
124
}
 
125
 
 
126
void
 
127
BamfLauncherIcon::OnActiveChanged (BamfView *view, gboolean active, gpointer data)
 
128
{
 
129
    BamfLauncherIcon *self = (BamfLauncherIcon *) data;
 
130
    self->SetActive (active);
 
131
}