Back to index

unity  6.0.0
DNDCollectionWindow.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003 * Copyright (C) 2011 Canonical Ltd
00004 *
00005 * This program is free software: you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License version 3 as
00007 * published by the Free Software Foundation.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 *
00017 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00018 */
00019 
00020 #include "DNDCollectionWindow.h"
00021 #include "unity-shared/WindowManager.h"
00022 
00023 namespace unity {
00024   
00025 NUX_IMPLEMENT_OBJECT_TYPE(DNDCollectionWindow);
00026 
00027 DNDCollectionWindow::DNDCollectionWindow()
00028   : nux::BaseWindow("")
00029   , display(NULL)
00030 {
00031   // Make it invisible...
00032   SetBackgroundColor(nux::Color(0x00000000));
00033   SetOpacity(0.0f);
00034   // ... and as big as the whole screen.
00035   SetGeometry(WindowManager::Default()->GetScreenGeometry());
00036   
00037   ShowWindow(true);
00038   PushToBack();
00039   // Hack to create the X Window as soon as possible.
00040   EnableInputWindow(true, "DNDCollectionWindow");
00041   EnableInputWindow(false, "DNDCollectionWindow");
00042   SetDndEnabled(false, true);
00043   
00044   WindowManager::Default()->window_moved.connect(sigc::mem_fun(this, &DNDCollectionWindow::OnWindowMoved));
00045 }
00046 
00047 DNDCollectionWindow::~DNDCollectionWindow()
00048 {
00049   for (auto it : mimes_)
00050     g_free(it);
00051 }
00052 
00059 void DNDCollectionWindow::OnWindowMoved(guint32 xid)
00060 {
00061   if (xid == GetInputWindowId() && display() != NULL)
00062   {
00063     // Create a fake mouse move because sometimes an extra one is required.
00064     XWarpPointer(display(), None, None, 0, 0, 0, 0, 0, 0);
00065     XFlush(display());
00066   }
00067 }
00068 
00069 void DNDCollectionWindow::Collect()
00070 {
00071   // Using PushToFront we're sure that the window is shown over the panel window,
00072   // the launcher window and the dash window. Don't forget to call PushToBack as
00073   // soon as possible.
00074   PushToFront();
00075   EnableInputWindow(true, "DndCollectionWindow");
00076 }
00077 
00078 void DNDCollectionWindow::ProcessDndMove(int x, int y, std::list<char*> mimes)
00079 {
00080   // Hide the window as soon as possible.
00081   PushToBack();
00082   EnableInputWindow(false, "DNDCollectionWindow");
00083   
00084   // Free mimes_ before fill it again.                       
00085   for (auto it : mimes_)
00086     g_free(it);
00087   mimes_.clear();
00088 
00089   // Duplicate the list.
00090   for (auto it : mimes)
00091     mimes_.push_back(g_strdup(it));
00092   
00093   // Emit the collected signal.
00094   collected.emit(mimes_);
00095 }
00096   
00097 } // namespace unity