./ 0000755 0000041 0000041 00000000000 13264221010 011232 5 ustar www-data www-data ./CMakeLists.txt 0000644 0000041 0000041 00000026643 13264221007 014013 0 ustar www-data www-data project (unity)
cmake_minimum_required(VERSION 2.8.9)
include (cmake/Documentation.cmake)
include (cmake/pch.cmake)
include (GNUInstallDirs)
#
# Base bits
#
set (PROJECT_NAME "unity")
set (UNITY_MAJOR 7)
set (UNITY_MINOR 5)
set (UNITY_MICRO 0)
set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")
set (UNITY_API_VERSION "6.0")
set (UNITY_COMPONENTS_VERSION "6")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGNOME_DESKTOP_USE_UNSTABLE_API -std=c++11 -fno-permissive")
set (CMAKE_CXX_FLAGS_DEBUG "-g3 -DUNITY_DEBUG_BUILD")
set (CMAKE_CXX_FLAGS_RELEASE "")
option(
ENABLE_X_SUPPORT
"Enable X.org support in unity"
ON
)
option(
ENABLE_UNIT_TESTS
"Enable Unity Unit Tests"
ON
)
# This is due to bug lp:668799 - qemu-arm segfaults executing msgmerge
option(
I18N_SUPPORT
"Enable I18N, do the .po file thing."
ON
)
option(
ENABLE_NETWORKAREAREGION_PLUGIN
"Enable Unity Network Area region Plugin"
OFF
)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set (PIC_FLAGS "-fPIC")
endif()
if (ENABLE_X_SUPPORT)
add_definitions(-DUSE_X11)
message("Unity is configured with support for X.org")
else ()
message("Unity is configured with without X.org")
add_definitions(-DNO_X11)
endif ()
if (BUILD_GLES)
add_definitions(-DNUX_OPENGLES_20)
add_definitions(-DUSE_GLES)
set (UNITY_STANDALONE_LADD "unity-core-${UNITY_API_VERSION};m;pthread;dl")
else ()
set (UNITY_STANDALONE_LADD "unity-core-${UNITY_API_VERSION};m;pthread;dl;GL;GLU")
endif ()
if (CMAKE_BUILD_TYPE MATCHES coverage)
set (COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
# FIXME: Read below
# set (COVERAGE_INFO_FILE "${CMAKE_BINARY_DIR}/coverage-html.info")
# set (COVERAGE_HTML_DIR "${CMAKE_BINARY_DIR}/coverage-html")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage" )
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" )
find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
if (NOT GCOVR_EXECUTABLE)
message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not found.")
else ()
message (STATUS "Enabling XML coverage report")
add_custom_target (coverage-xml
COMMAND "${GCOVR_EXECUTABLE}" --exclude="tests.*" --exclude="obj-.*" -x -r "${CMAKE_SOURCE_DIR}" -o "${COVERAGE_XML_FILE}")
endif()
# FIXME: This got commented out, as it forces a strict dependency on lcov
# find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${LCOV_ROOT}/bin")
# find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT} "${GENHTML_ROOT}/bin")
# if (NOT LCOV_EXECUTABLE)
# message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not found.")
# elseif (NOT GENHTML_EXECUTABLE)
# message(FATAL_ERROR "Cannot enable coverage targets because genhtml was not found.")
# else ()
# message (STATUS "Enabling HTML coverage report")
# add_custom_target (coverage-html
# COMMAND "${LCOV_EXECUTABLE}" --directory "${CMAKE_BINARY_DIR}" --capture --output-file "${COVERAGE_INFO_FILE}"
# COMMAND "${GENHTML_EXECUTABLE}" --output-directory "${COVERAGE_HTML_DIR}" "${COVERAGE_INFO_FILE}")
# endif()
endif (CMAKE_BUILD_TYPE MATCHES coverage)
#
# Niceties
#
set (ARCHIVE_NAME unity-${UNITY_VERSION})
add_custom_target (pre-distcheck
COMMAND echo ""
&& echo "• Releasing Unity ${UNITY_VERSION}"
&& cd ${CMAKE_SOURCE_DIR}
&& echo "• Generating ChangeLog"
&& bzr log --gnu-changelog > ChangeLog
&& echo "• Generating AUTHORS"
&& bzr log --long --levels=0 | grep -e "^\\s*author:" | cut -d ":" -f 2 | sed "s/,/\n/g" | sed -r -f AUTHOR-glue | sort -u | uniq -i > AUTHORS
&& echo "• Running Distcheck"
)
add_custom_target (dist
COMMAND echo "• Creating Tarball"
&& bzr export --root=${ARCHIVE_NAME} ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
&& echo "• Signing Tarball"
&& gpg --armor --sign --detach-sig ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(dist pre-distcheck)
add_custom_target (distcheck
COMMAND cd ${CMAKE_BINARY_DIR}
&& rm -rf ${ARCHIVE_NAME}
&& tar xf ${ARCHIVE_NAME}.tar.bz2
&& mkdir ${ARCHIVE_NAME}/build
&& cd ${ARCHIVE_NAME}/build
&& cmake -DCMAKE_INSTALL_PREFIX=../install -DGSETTINGS_LOCALINSTALL=ON .. -DCMAKE_MODULE_PATH=/usr/share/cmake
&& make
&& make install
&& make check-headless
)
add_dependencies(distcheck dist)
add_custom_target (post-distcheck
COMMAND echo "• Committing Release"
&& bzr commit -m\"Release ${UNITY_VERSION}\" --unchanged
&& echo "• Tagging Release"
&& bzr tag ${UNITY_VERSION}
&& echo "• Unity ${UNITY_VERSION} is ready for release."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(post-distcheck distcheck)
add_custom_target (release)
add_dependencies (release distcheck)
#
# config.h
#
set (VERSION "${UNITY_VERSION}")
set (PREFIXPATH "${CMAKE_INSTALL_PREFIX}")
set (UNITY_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME}")
set (UNITY_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
set (UNITY_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
set (PKGDATADIR "${UNITY_DATADIR}/icons")
set (SOURCEDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
set (BUILDDIR "${CMAKE_BINARY_DIR}")
set (TESTDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/data")
set (LOCALE_DIR "${CMAKE_INSTALL_FULL_LOCALEDIR}")
# specify the domain directly rather than refering to a variable
# like ${PROJECT_NAME} to no confuse dh_translations
set (GETTEXT_PACKAGE "unity")
find_package (PkgConfig)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gtk+-3.0 --variable prefix OUTPUT_VARIABLE GTK_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} unity --variable lensesdir OUTPUT_VARIABLE LENSES_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable indicatordir OUTPUT_VARIABLE INDICATORDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable iconsdir OUTPUT_VARIABLE INDICATORICONDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable prefix OUTPUT_VARIABLE INDICATORPREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
set (INDICATOR_SERVICE_DIR "${INDICATORPREFIX}/share/${PROJECT_NAME}/indicators")
configure_file (${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
#
# i18n
#
find_package (Gettext REQUIRED)
set (COMPIZ_I18N_DIR ${CMAKE_SOURCE_DIR}/po)
add_custom_command (OUTPUT ${CMAKE_SOURCE_DIR}/po/${PROJECT_NAME}.pot
COMMAND xgettext -c --from-code=UTF-8 --files-from ${CMAKE_SOURCE_DIR}/po/POTFILES.in --keyword=_ -o ${CMAKE_SOURCE_DIR}/po/${PROJECT_NAME}.pot --copyright-holder="Canonical Ltd" --msgid-bugs-address="ayatana-dev@lists.launchpad.net" --no-wrap --no-location
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if (I18N_SUPPORT)
if (GETTEXT_FOUND)
set (HAVE_GETTEXT true)
file (GLOB _translations ${CMAKE_SOURCE_DIR}/po/*.po)
GETTEXT_CREATE_TRANSLATIONS (${CMAKE_SOURCE_DIR}/po/${PROJECT_NAME}.pot
ALL ${_translations})
endif (GETTEXT_FOUND)
endif()
#
# Enable or disable boot logging
#
option (BOOT_LOGGER "Enable startup performance logging" OFF)
if (BOOT_LOGGER)
SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER")
endif (BOOT_LOGGER)
SET (MAINTAINER_CXXFLAGS "-Werror -Wall -Wcast-align -Wempty-body -Wformat-security -Winit-self -Warray-bounds -Wno-error=deprecated-declarations")
option (DISABLE_ERROR_ON_LOCAL_TYPEDEFS_WARNINGS "Disable errors when local typedefs are unused" ON)
if (DISABLE_ERROR_ON_LOCAL_TYPEDEFS_WARNINGS)
SET (MAINTAINER_CXXFLAGS "${MAINTAINER_CXXFLAGS} -Wno-error=unused-local-typedefs")
endif (DISABLE_ERROR_ON_LOCAL_TYPEDEFS_WARNINGS)
option (DISABLE_MAINTAINER_CXXFLAGS "Disable maintainer CXXFlags" OFF)
if (DISABLE_MAINTAINER_CXXFLAGS)
SET (MAINTAINER_CXXFLAGS "")
endif (DISABLE_MAINTAINER_CXXFLAGS)
# Make sure these flags are used for every build.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MAINTAINER_CXXFLAGS}")
#
# Compiz Plugins
#
set(UNITY_PROTOCOL_PRIVATE_DEPS unity-protocol-private>=7.1.0)
set(UNITY_PLUGIN_SHARED_DEPS
${UNITY_PROTOCOL_PRIVATE_DEPS}
appstream-glib
atk
atk-bridge-2.0
cairo>=1.13.1
dbusmenu-glib-0.4
dee-1.0
gio-2.0>=2.30.0
gio-unix-2.0
gmodule-2.0
gthread-2.0
gtk+-3.0>=3.1
indicator3-0.4>=0.4.90
json-glib-1.0
libbamf3>=0.5.3
gnome-desktop-3.0
libnotify
libstartup-notification-1.0
nux-4.0>=4.0.5
sigc++-2.0>=2.4.0
unity-misc>=0.4.0
xpathselect=1.4
zeitgeist-2.0
)
set(UNITY_PLUGIN_DEPS ${UNITY_PLUGIN_SHARED_DEPS})
if(ENABLE_X_SUPPORT)
set(UNITY_PLUGIN_DEPS
${UNITY_PLUGIN_DEPS}
compiz>=0.9.11
libgeis
x11
xfixes
xi>=1.6.99.1
xrender>=0.9
)
endif ()
pkg_check_modules (CACHED_UNITY_DEPS REQUIRED ${UNITY_PLUGIN_DEPS})
pkg_check_modules (CACHED_UNITY_PRIVATE_DEPS REQUIRED ${UNITY_PROTOCOL_PRIVATE_DEPS})
find_library (UNITY_PROTOCOL_PRIVATE_LIB unity-protocol-private ${CACHED_UNITY_PRIVATE_DEPS_LIBDIR} ${CACHED_UNITY_PRIVATE_DEPS_LIBRARY_DIRS})
set(UNITY_STANDALONE_LADD ${UNITY_STANDALONE_LADD} ${UNITY_PROTOCOL_PRIVATE_LIB})
add_subdirectory(a11y)
add_subdirectory(unity-shared)
add_subdirectory(dash)
add_subdirectory(launcher)
add_subdirectory(data)
if (ENABLE_X_SUPPORT)
add_subdirectory(hud)
add_subdirectory(lockscreen)
add_subdirectory(panel)
add_subdirectory(decorations)
add_subdirectory(plugins/unityshell)
add_subdirectory(plugins/unity-mt-grab-handles)
add_subdirectory(shortcuts)
add_subdirectory(shutdown)
add_subdirectory(unity-standalone)
if (ENABLE_NETWORKAREAREGION_PLUGIN)
add_subdirectory(plugins/networkarearegion)
endif (ENABLE_NETWORKAREAREGION_PLUGIN)
endif ()
add_subdirectory(doc)
add_subdirectory(services)
add_subdirectory(tools)
add_subdirectory(UnityCore)
add_subdirectory(guides)
add_subdirectory(gnome)
if (ENABLE_UNIT_TESTS)
add_subdirectory(tests)
else (ENABLE_UNIT_TESTS)
set (MISSING_TESTS_MSG "-- Tests disabled, compile with -DENABLE_UNIT_TESTS=ON")
add_custom_target (check COMMAND echo ${MISSING_TESTS_MSG})
add_custom_target (check-headless COMMAND echo ${MISSING_TESTS_MSG})
add_custom_target (gcheck COMMAND echo ${MISSING_TESTS_MSG})
endif (ENABLE_UNIT_TESTS)
# Resources
install (FILES resources/dash-widgets.json DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/themes)
file (GLOB _datafiles "${CMAKE_CURRENT_SOURCE_DIR}/resources/*")
install (FILES ${_datafiles} DESTINATION ${PKGDATADIR})
#
# docs
#
# check if doxygen is even installed
find_package(Doxygen)
if (DOXYGEN_FOUND STREQUAL "NO")
message("Doxygen not found. Documentation will not be built")
endif (DOXYGEN_FOUND STREQUAL "NO")
if (DOXYGEN_FOUND STREQUAL "YES")
set(TOP_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR})
# prepare doxygen configuration file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# add doxygen as target
add_custom_target(doxygen ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# cleanup $build/api-doc on "make clean"
set_property(DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES api-doc)
endif (DOXYGEN_FOUND STREQUAL "YES")
./unity-standalone/ 0000755 0000041 0000041 00000000000 13264221010 014530 5 ustar www-data www-data ./unity-standalone/CMakeLists.txt 0000644 0000041 0000041 00000001662 13264221007 017303 0 ustar www-data www-data set(UNITY_SRC ../plugins/unityshell/src)
set (CFLAGS
${CACHED_UNITY_DEPS_CFLAGS}
${CACHED_UNITY_DEPS_CFLAGS_OTHER}
${PIC_FLAGS}
)
string (REPLACE ";" " " CFLAGS "${CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")
set (LIBS ${CACHED_UNITY_DEPS_LDFLAGS} ${UNITY_STANDALONE_LADD})
include_directories (.. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR})
#
# Headers & Sources
#
set (STANDALONE_SOURCES
StandaloneUnity.cpp
)
add_executable (unity-standalone StandaloneUnity.cpp)
# This makes linker to include library dir in RUNPATH
find_library (COMPIZ_LIB compiz_core ${COMPIZ_LIBDIR})
target_link_libraries (unity-standalone
dash-lib
launcher-lib
panel-lib
unity-shared
unity-shared-bamf
unity-shared-standalone
${COMPIZ_LIB})
./unity-standalone/StandaloneUnity.cpp 0000644 0000041 0000041 00000015572 13264221007 020375 0 ustar www-data www-data /*
* Copyright 2010 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
* Neil Jagdish Patel
*
*/
#include
#include
#include
#include
#include
#include
#include
#include "dash/DashController.h"
#include "dash/DashView.h"
#include "launcher/FavoriteStoreGSettings.h"
#include "launcher/Launcher.h"
#include "launcher/LauncherController.h"
#include "panel/PanelController.h"
#include "panel/PanelView.h"
#include "unity-shared/BGHash.h"
#include "unity-shared/BackgroundEffectHelper.h"
#include "unity-shared/DashStyle.h"
#include "unity-shared/FontSettings.h"
#include "unity-shared/KeyGrabber.h"
#include "unity-shared/MenuManager.h"
#include "unity-shared/PanelStyle.h"
#include "unity-shared/ThumbnailGenerator.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/UnitySettings.h"
namespace
{
static int display_width = 1200;
static int display_height = 720;
static gboolean no_window_decorations = FALSE;
static gboolean force_tv = FALSE;
static GOptionEntry entries[] =
{
{"width", 'w', 0, G_OPTION_ARG_INT, &display_width, "Display width", NULL},
{"height", 'h', 0, G_OPTION_ARG_INT, &display_height, "Display height", NULL},
{"no-window-decorations", 'd', 0, G_OPTION_ARG_NONE, &no_window_decorations, "Disables the window decorations", NULL},
{"force-tv", 't', 0, G_OPTION_ARG_NONE, &force_tv, "Forces the TV interface", NULL},
{NULL}
};
}
using namespace unity;
struct StandaloneDndManager : XdndManager
{
int Monitor() const { return 0; }
};
struct StandaloneKeyGrabber : key::Grabber
{
CompAction::Vector& GetActions() override { return noActions(); }
uint32_t AddAction(CompAction const&) override { return 0; };
bool RemoveAction(CompAction const&) override { return false; };
bool RemoveAction(uint32_t id) override { return false; };
};
class UnityStandalone
{
public:
UnityStandalone ();
~UnityStandalone ();
static void InitWindowThread (nux::NThread* thread, void* InitData);
void Init ();
launcher::Controller::Ptr launcher_controller;
dash::Controller::Ptr dash_controller;
panel::Controller::Ptr panel_controller;
};
UnityStandalone::UnityStandalone ()
{
}
UnityStandalone::~UnityStandalone ()
{
}
void UnityStandalone::Init ()
{
auto xdnd_manager = std::make_shared();
auto edge_barriers = std::make_shared();
auto indicators = std::make_shared();
auto key_grabber = std::make_shared();
auto menu_manager = std::make_shared(indicators, key_grabber);
launcher_controller = std::make_shared(xdnd_manager, edge_barriers);
panel_controller = std::make_shared(menu_manager, edge_barriers);
dash_controller = std::make_shared();
}
void UnityStandalone::InitWindowThread(nux::NThread* thread, void* InitData)
{
UnityStandalone *self = static_cast(InitData);
self->Init();
}
class UnityStandaloneTV
{
public:
UnityStandaloneTV();
~UnityStandaloneTV();
static void InitWindowThread (nux::NThread* thread, void* InitData);
void Init();
launcher::Controller::Ptr launcher_controller;
dash::Controller::Ptr dash_controller;
};
UnityStandaloneTV::UnityStandaloneTV() {};
UnityStandaloneTV::~UnityStandaloneTV() {};
void UnityStandaloneTV::Init()
{
auto xdnd_manager = std::make_shared();
auto edge_barriers = std::make_shared();
launcher_controller = std::make_shared(xdnd_manager, edge_barriers);
dash_controller = std::make_shared();
UBusManager().SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION, nullptr);
}
void UnityStandaloneTV::InitWindowThread(nux::NThread* thread, void* InitData)
{
UnityStandaloneTV *self = static_cast(InitData);
self->Init();
}
int main(int argc, char **argv)
{
nux::WindowThread* wt = NULL;
GError *error = NULL;
GOptionContext *context;
nux::NuxInitialize(0);
nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
context = g_option_context_new("- Unity standalone");
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
g_option_context_add_group(context, gtk_get_option_group(TRUE));
g_option_context_parse(context, &argc, &argv, &error);
if (error != NULL)
{
g_print("Option parsiong failed: %s\n", error->message);
g_error_free(error);
exit(1);
}
gtk_init(&argc, &argv);
BGHash bghash;
FontSettings font_settings;
// The instances for the pseudo-singletons.
Settings settings;
settings.is_standalone = true;
if (force_tv) Settings::Instance().form_factor(FormFactor::TV);
dash::Style dash_style;
panel::Style panel_style;
unity::ThumbnailGenerator thumbnail_generator;
internal::FavoriteStoreGSettings favorite_store;
BackgroundEffectHelper::blur_type = BLUR_NONE;
if (!force_tv)
{
UnityStandalone *standalone_runner = new UnityStandalone();
wt = nux::CreateNuxWindow("standalone-unity",
display_width, display_height,
(no_window_decorations) ? nux::WINDOWSTYLE_NOBORDER : nux::WINDOWSTYLE_NORMAL,
0, /* no parent */
false,
&UnityStandalone::InitWindowThread,
standalone_runner);
}
else
{
//TODO - we should be able to pass in a monitor so that we can make the window
//the size of the monitor and position the window on the monitor correctly.
UnityStandaloneTV *standalone_runner = new UnityStandaloneTV();
wt = nux::CreateNuxWindow("standalone-unity-tv",
display_width, display_height,
(no_window_decorations) ? nux::WINDOWSTYLE_NOBORDER : nux::WINDOWSTYLE_NORMAL,
0, /* no parent */
false,
&UnityStandaloneTV::InitWindowThread,
standalone_runner);
}
wt->Run(NULL);
delete wt;
return 0;
}
./INSTALL 0000644 0000041 0000041 00000011756 13264221007 012303 0 ustar www-data www-data Install
--------------------------------------------------------------------------------
• Notes
- libunity is an independant library which has a client side API for talking
to Unity. However it does not depend on the main Unity codebase and the
main Unity codebase does not depend on it.
- Unity and it's desktop environment modules are all modules of Compiz. We use
a patched version of Compiz which uses the GLib main loop instead of the
custom Compiz main loop. This allows us to use GNOME libraries easily inside
the Unity plugins.
We are currently working on getting this patch upstreamed, but until then
you will need to build this special version of Compiz.
- libunity is written in Vala and the rest of Unity in C++/C.
- Unity depends on a library called Nux (lp:nux) which let's us do OpenGL
layouts quickly and efficiently.
• Dependencies
These are in Debian package name form, but it should be easy enough to
translate them to other systems:
libglib2.0-dev libgdk-pixbuf2.0-dev libcairo2-dev libpng12-dev libglew1.5-dev
libglewmx1.5-dev libxxf86vm-dev libgl1-mesa-dev libsigc++-2.0-dev
libpango1.0-dev doxygen cmake pkg-config intltool
libbamf-dev gsettings-desktop-schemas-dev libgconf2-dev libglib2.0-dev
libdbusmenu-glib-dev libgtk2.0-dev libdee-dev libindicator-dev
libboost-dev libboost-serialization-dev libmetacity-dev python-dev cython
However, as with any project, it's probably best to just run autogen/cmake
and figure out what you need/is missing. If your distro supports grabbing
all the packages needed to build a package, then at least do that for
Compiz, as I'm not going to detail everything it needs here.
In case your distro isn't packaging all the Ayatana software, these links
might come in handy:
https://launchpad.net/dee
https://launchpad.net/bamf
https://launchpad.net/libindicator
Also, although we don't hard depend on them, having a few indicators installed
will make your experience better:
https://launchpad.net/indicator-appmenu
https://launchpad.net/indicator-application
https://launchpad.net/indicator-network
https://launchpad.net/indicator-sound
https://launchpad.net/indicator-messages
https://launchpad.net/indicator-datetime
https://launchpad.net/indicator-me
https://launchpad.net/indicator-session
• Build Compiz GLib
This is taken from http://wiki.ubuntu.com/Unity/InstallationGuideFromSource and
was originally authored by Sam:
core:
git clone git://git.compiz.org/users/dbo/compiz-with-glib-mainloop
cd compiz-with-glib-mainloop
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/unity
make
sudo make findcompiz_install
sudo make install
exporting paths:
export PKG_CONFIG_PATH=/opt/unity/lib/pkgconfig:${PKG_CONFIG_PATH}
export LD_LIBRARY_PATH=/opt/unity/lib:${LD_LIBRARY_PATH}
export LD_RUN_PATH=/opt/unity/lib:${LD_RUN_PATH}
libcompizconfig:
git clone git://git.compiz.org/compiz/compizconfig/libcompizconfig
cd libcompizconfig
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/unity
make
sudo make install
compizconfig-python:
git clone git://git.compiz.org/compiz/compizconfig/compizconfig-python
cd compizconfig-python
python setup.py install --prefix=/opt/unity
ccsm:
git clone git://git.compiz.org/compiz/compizconfig/ccsm
cd ccsm
python setup.py install --prefix=/opt/unity
plugins-main:
git clone git://git.compiz.org/compiz/plugins-main
cd plugins-main
git submodule init
git pull origin master
git submodule update
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/unity
make
sudo make install
plugins-extra:
git clone git://git.compiz.org/compiz/plugins-extra
cd plugins-extra
git submodule init
git pull origin master
git submodule update
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/unity
make
sudo make install
• Build Nux
bzr branch lp:nux
cd nux
./autogen.sh --disable-documentation --prefix=/opt/unity
make
sudo make install
• Build Unity
bzr branch lp:unity
cd unity
mkdir build; cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCOMPIZ_PLUGIN_INSTALL_TYPE=package -DCMAKE_INSTALL_PREFIX=/opt/unity
make
sudo make install
• Cleanup
unset PKG_CONFIG_PATH
unset LD_LIBRARY_PATH
unset LD_RUN_PATH
• Testing
add this to your /home/$USER/.bashrc
function compiz-unity-setup-env
{
export PATH=/opt/unity/bin:${PATH}
export PYTHONPATH=/opt/unity/lib/python2.6/site-packages
}
Logout, login, then in a terminal do
$ compiz-unity-setup-env
$ compiz --replace cpp &
$ ccsm
And then use the CompizConfig Settings Window to search for and enable the Unity plugin!
• Bugs
If you find bugs in this installation guide or in Unity itself, please report them at
https://launchpad.net/unity/+filebug
./README 0000644 0000041 0000041 00000001327 13264221007 012123 0 ustar www-data www-data Unity
--------------------------------------------------------------------------------
• Installation
Please see INSTALL or http://wiki.ubuntu.com/Unity/InstallationGuideFromSource
• Tests
- You can run `make check` in the build directory to run all GTester tests
- In the build directory, ./tests/test-panel will start the panel in
standalone mode, which is great for testing
• Environmental Variables
PANEL_USE_LOCAL_SERVICE=${anything}
Makes the panel run the unity-panel-service directly instead of through
D-Bus activation. This is used for testing how the panel reacts when it
starts before the service does.
./config.h.cmake 0000644 0000041 0000041 00000001523 13264221007 013736 0 ustar www-data www-data #ifndef CONFIG_H
#define CONFIG_H
#cmakedefine PREFIXPATH "@PREFIXPATH@"
#cmakedefine UNITY_DATADIR "@UNITY_DATADIR@"
#cmakedefine UNITY_LIBDIR "@UNITY_LIBDIR@"
#cmakedefine UNITY_INSTALL_LIBDIR "@UNITY_INSTALL_LIBDIR@"
#cmakedefine PKGDATADIR "@PKGDATADIR@"
#cmakedefine LOCALE_DIR "@LOCALE_DIR@"
#cmakedefine VERSION "@VERSION@"
#cmakedefine BUILDDIR "@BUILDDIR@"
#cmakedefine SOURCEDATADIR "@SOURCEDATADIR@"
#cmakedefine TESTDATADIR "@TESTDIRDIR@"
#cmakedefine GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
#cmakedefine LENSES_DIR "@LENSES_DIR@"
#cmakedefine GTK_PREFIX "@GTK_PREFIX@"
#ifndef INDICATORDIR
#cmakedefine INDICATORDIR "@INDICATORDIR@"
#endif
#ifndef INDICATORICONDIR
#cmakedefine INDICATORICONDIR "@INDICATORICONDIR@"
#endif
#ifndef INDICATOR_SERVICE_DIR
#cmakedefine INDICATOR_SERVICE_DIR "@INDICATOR_SERVICE_DIR@"
#endif
#endif // CONFIG_H
./dash/ 0000755 0000041 0000041 00000000000 13264221010 012151 5 ustar www-data www-data ./dash/PlacesGroup.cpp 0000755 0000041 0000041 00000052471 13264221007 015123 0 ustar www-data www-data /*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include
#include
#include
#include "PlacesGroup.h"
#include
#include "config.h"
#include
#include
#include "unity-shared/StaticCairoText.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/GraphicsUtils.h"
#include "ResultView.h"
#include "ResultViewGrid.h"
#include "ResultRendererTile.h"
#include "ResultRendererHorizontalTile.h"
#include "CoverflowResultView.h"
#include "FilterBasicButton.h"
DECLARE_LOGGER(logger, "unity.dash.placesgroup");
namespace unity
{
namespace dash
{
namespace
{
const nux::Color EXPAND_DEFAULT_TEXT_COLOR(1.0f, 1.0f, 1.0f, 0.5f);
const float EXPAND_DEFAULT_ICON_OPACITY = 0.5f;
// Category highlight
const RawPixel HIGHLIGHT_RIGHT_PADDING = 10_em;
const RawPixel HIGHLIGHT_HEIGHT = 24_em;
const RawPixel HIGHLIGHT_LEFT_PADDING = 10_em;
const RawPixel SPACE_BETWEEN_CHILDREN = 10_em;
const RawPixel TEXT_INTERNAL_MARGIN = 15_em;
const RawPixel EXPAND_INTERNAL_MARGIN = 8_em;
const double DEFAULT_SCALE = 1.0;
// Font
const char* const NAME_LABEL_FONT = "Ubuntu 13"; // 17px = 13
const char* const EXPANDER_LABEL_FONT = "Ubuntu 10"; // 13px = 10
}
class HeaderView : public nux::View
{
public:
HeaderView(NUX_FILE_LINE_DECL)
: nux::View(NUX_FILE_LINE_PARAM)
{
SetAcceptKeyNavFocusOnMouseDown(false);
SetAcceptKeyNavFocusOnMouseEnter(true);
}
protected:
void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
{
};
void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw)
{
graphics_engine.PushClippingRectangle(GetGeometry());
nux::GetPainter().PushPaintLayerStack();
if (GetLayout())
{
GetLayout()->ProcessDraw(graphics_engine, force_draw);
}
nux::GetPainter().PopPaintLayerStack();
graphics_engine.PopClippingRectangle();
}
bool AcceptKeyNavFocus()
{
return true;
}
nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type)
{
if (event_type != nux::EVENT_MOUSE_WHEEL &&
TestMousePointerInclusion(mouse_position, event_type))
return this;
else
return nullptr;
}
};
NUX_IMPLEMENT_OBJECT_TYPE(PlacesGroup);
PlacesGroup::PlacesGroup(dash::StyleInterface& style)
: nux::View(NUX_TRACKER_LOCATION),
scale(DEFAULT_SCALE),
_style(style),
_child_layout(nullptr),
_child_view(nullptr),
_using_filters_background(false),
_is_expanded(false),
_is_expanded_pushed(false),
_n_visible_items_in_unexpand_mode(0),
_n_total_items(0),
_coverflow_enabled(false),
_disabled_header_count(false)
{
SetAcceptKeyNavFocusOnMouseDown(false);
SetAcceptKeyNavFocusOnMouseEnter(false);
scale.changed.connect(sigc::mem_fun(this, &PlacesGroup::UpdateScale));
nux::ROPConfig rop;
rop.Blend = true;
rop.SrcBlend = GL_ONE;
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
nux::TexCoordXForm texxform;
_background_layer.reset(new nux::TextureLayer(_style.GetCategoryBackgroundNoFilters()->GetDeviceTexture(),
texxform,
nux::color::White,
false,
rop));
_group_layout = new nux::VLayout("", NUX_TRACKER_LOCATION);
// Spacelayout size is updated in UpdatePlacesGroupSize
_space_layout = new nux::SpaceLayout(0, 0, 0, 0);
_group_layout->AddLayout(_space_layout, 0);
_header_view = new HeaderView(NUX_TRACKER_LOCATION);
_group_layout->AddView(_header_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
_header_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
_header_layout->SetLeftAndRightPadding(_style.GetCategoryHeaderLeftPadding().CP(scale), 0);
_header_view->SetLayout(_header_layout);
_icon = new IconTexture("", _style.GetCategoryIconSize().CP(scale));
_header_layout->AddView(_icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
_text_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
_header_layout->AddLayout(_text_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
_name = new StaticCairoText("", NUX_TRACKER_LOCATION);
_name->SetFont(NAME_LABEL_FONT);
_name->SetLines(-1);
_name->SetTextEllipsize(StaticCairoText::NUX_ELLIPSIZE_END);
_name->SetTextAlignment(StaticCairoText::NUX_ALIGN_LEFT);
_text_layout->AddView(_name, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
_expand_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
_text_layout->AddLayout(_expand_layout, 0, nux::MINOR_POSITION_END, nux::MINOR_SIZE_MATCHCONTENT);
_expand_label_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
_expand_layout->AddLayout(_expand_label_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
_expand_label = new StaticCairoText("", NUX_TRACKER_LOCATION);
_expand_label->SetFont(EXPANDER_LABEL_FONT);
_expand_label->SetLines(-1);
_expand_label->SetTextEllipsize(StaticCairoText::NUX_ELLIPSIZE_END);
_expand_label->SetTextAlignment(StaticCairoText::NUX_ALIGN_LEFT);
_expand_label->SetTextColor(EXPAND_DEFAULT_TEXT_COLOR);
_expand_label_layout->AddView(_expand_label, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
_expand_icon = new IconTexture(_style.GetGroupExpandIcon());
_expand_icon->SetDrawMode(IconTexture::DrawMode::STRETCH_WITH_ASPECT);
_expand_icon->SetOpacity(EXPAND_DEFAULT_ICON_OPACITY);
_expand_icon->SetVisible(false);
_expand_layout->AddView(_expand_icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
SetLayout(_group_layout);
// don't need to disconnect these signals as they are disconnected when this object destroys the contents
_header_view->mouse_click.connect(sigc::mem_fun(this, &PlacesGroup::RecvMouseClick));
_header_view->key_nav_focus_change.connect(sigc::mem_fun(this, &PlacesGroup::OnLabelFocusChanged));
_header_view->key_nav_focus_activate.connect(sigc::mem_fun(this, &PlacesGroup::OnLabelActivated));
_icon->mouse_click.connect(sigc::mem_fun(this, &PlacesGroup::RecvMouseClick));
_name->mouse_click.connect(sigc::mem_fun(this, &PlacesGroup::RecvMouseClick));
_expand_label->mouse_click.connect(sigc::mem_fun(this, &PlacesGroup::RecvMouseClick));
_expand_icon->mouse_click.connect(sigc::mem_fun(this, &PlacesGroup::RecvMouseClick));
key_nav_focus_change.connect([this](nux::Area* area, bool has_focus, nux::KeyNavDirection direction)
{
if (!has_focus)
return;
if(direction == nux::KEY_NAV_UP)
nux::GetWindowCompositor().SetKeyFocusArea(_child_view, direction);
else
{
if (IsExpandable())
nux::GetWindowCompositor().SetKeyFocusArea(GetHeaderFocusableView(), direction);
else
nux::GetWindowCompositor().SetKeyFocusArea(_child_view, direction);
}
});
UpdatePlacesGroupSize();
}
void
PlacesGroup::UpdatePlacesGroupSize()
{
int icon_size = _style.GetCategoryIconSize().CP(scale);
int top_space = _style.GetPlacesGroupTopSpace().CP(scale);
_space_layout->SetMinimumSize(top_space, top_space);
_space_layout->SetMaximumSize(top_space, top_space);
_header_layout->SetSpaceBetweenChildren(SPACE_BETWEEN_CHILDREN.CP(scale()));
_header_layout->SetLeftAndRightPadding(_style.GetCategoryHeaderLeftPadding().CP(scale), 0);
_icon->SetMinMaxSize(icon_size, icon_size);
_text_layout->SetHorizontalInternalMargin(TEXT_INTERNAL_MARGIN.CP(scale()));
_expand_layout->SetHorizontalInternalMargin(EXPAND_INTERNAL_MARGIN.CP(scale()));
}
void
PlacesGroup::UpdateScale(double scale)
{
_name->SetMinimumSize(nux::AREA_MIN_WIDTH, nux::AREA_MIN_HEIGHT);
_name->SetMaximumSize(nux::AREA_MAX_WIDTH, nux::AREA_MAX_HEIGHT);
_name->SetScale(scale);
_expand_label->SetScale(scale);
_icon->SetSize(_style.GetCategoryIconSize().CP(scale));
_icon->ReLoadIcon();
auto const& arrow = _expand_icon->texture();
_expand_icon->SetMinMaxSize(RawPixel(arrow->GetWidth()).CP(scale), RawPixel(arrow->GetHeight()).CP(scale));
if (_child_view)
_child_view->scale = scale;
ComputeContentSize();
UpdatePlacesGroupSize();
UpdateResultViewPadding();
}
void
PlacesGroup::OnLabelActivated(nux::Area* label)
{
SetExpanded(!_is_expanded);
}
void
PlacesGroup::OnLabelFocusChanged(nux::Area* label, bool has_focus, nux::KeyNavDirection direction)
{
if (HeaderHasKeyFocus())
{
_ubus.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
g_variant_new("(iiii)", 0, 0, 0, 0));
}
QueueDraw();
}
void
PlacesGroup::SetName(std::string const& name)
{
if (_cached_name != name)
{
_cached_name = name;
_name->SetText(glib::String(g_markup_escape_text(name.c_str(), -1)).Str());
}
}
void PlacesGroup::SetHeaderCountVisible(bool disable)
{
_disabled_header_count = !disable;
Relayout();
}
StaticCairoText*
PlacesGroup::GetLabel()
{
return _name;
}
StaticCairoText*
PlacesGroup::GetExpandLabel()
{
return _expand_label;
}
void
PlacesGroup::SetIcon(std::string const& path_to_emblem)
{
_icon->SetByIconName(path_to_emblem, _style.GetCategoryIconSize().CP(scale));
}
void
PlacesGroup::UpdateResultViewPadding()
{
if (_child_layout)
{
_child_layout->SetTopAndBottomPadding(_style.GetPlacesGroupResultTopPadding().CP(scale), 0);
_child_layout->SetLeftAndRightPadding(_style.GetPlacesGroupResultLeftPadding().CP(scale), 0);
}
}
void
PlacesGroup::SetChildView(dash::ResultView* view)
{
if (_child_view)
{
RemoveChild(_child_view);
}
if (_child_layout != NULL)
{
_group_layout->RemoveChildObject(_child_layout);
}
AddChild(view);
_child_view = view;
_child_view->scale = scale();
_child_layout = new nux::VLayout();
_child_layout->AddView(_child_view, 0);
UpdateResultViewPadding();
_group_layout->AddLayout(_child_layout, 1);
UpdateVisibleItems(view->results_per_row());
view->results_per_row.changed.connect(sigc::mem_fun(this, &PlacesGroup::UpdateVisibleItems));
QueueDraw();
}
void PlacesGroup::UpdateVisibleItems(int visible_items)
{
_n_visible_items_in_unexpand_mode = visible_items;
RefreshLabel();
}
dash::ResultView*
PlacesGroup::GetChildView()
{
return _child_view;
}
void PlacesGroup::SetChildLayout(nux::Layout* layout)
{
_group_layout->AddLayout(layout, 1);
QueueDraw();
}
void
PlacesGroup::RefreshLabel()
{
if (_disabled_header_count)
{
_expand_icon->SetVisible(false);
_expand_label->SetVisible(false);
return;
}
std::string result_string;
if (_n_visible_items_in_unexpand_mode < _n_total_items)
{
if (_is_expanded)
{
result_string = _("See fewer results");
}
else
{
LOG_TRACE(logger) << _n_total_items << " - " << _n_visible_items_in_unexpand_mode;
result_string = glib::String(g_strdup_printf(g_dngettext(GETTEXT_PACKAGE,
"See one more result",
"See %d more results",
_n_total_items - _n_visible_items_in_unexpand_mode),
_n_total_items - _n_visible_items_in_unexpand_mode)).Str();
}
}
bool visible = !(_n_visible_items_in_unexpand_mode >= _n_total_items && _n_total_items != 0);
_expand_icon->SetVisible(visible);
SetName(_cached_name);
_expand_label->SetText(result_string);
_expand_label->SetVisible(visible);
// See bug #748101 ("Dash - "See more..." line should be base-aligned with section header")
// We're making two assumptions here:
// [a] The font size _name is bigger than the font size of _expand_label
// [b] The bottom sides have the same y coordinate
int bottom_padding = _name->GetBaseHeight() - _name->GetBaseline() -
(_expand_label->GetBaseHeight() - _expand_label->GetBaseline());
_expand_label_layout->SetTopAndBottomPadding(0, bottom_padding);
QueueDraw();
}
void
PlacesGroup::Refresh()
{
RefreshLabel();
ComputeContentSize();
QueueDraw();
}
void
PlacesGroup::Relayout()
{
if (_relayout_idle)
return;
_relayout_idle.reset(new glib::Idle(glib::Source::Priority::HIGH));
_relayout_idle->Run(sigc::mem_fun(this, &PlacesGroup::OnIdleRelayout));
}
bool
PlacesGroup::OnIdleRelayout()
{
if (GetChildView())
{
Refresh();
QueueDraw();
_group_layout->QueueDraw();
GetChildView()->QueueDraw();
ComputeContentSize();
_relayout_idle.reset();
}
return false;
}
long PlacesGroup::ComputeContentSize()
{
long ret = nux::View::ComputeContentSize();
nux::Geometry const& geo = GetGeometry();
// only the width matters
if (_cached_geometry.GetWidth() != geo.GetWidth())
{
_focus_layer.reset(_style.FocusOverlay(geo.width -
HIGHLIGHT_LEFT_PADDING.CP(scale()) -
HIGHLIGHT_RIGHT_PADDING.CP(scale()),
HIGHLIGHT_HEIGHT.CP(scale())));
_cached_geometry = geo;
}
return ret;
}
void PlacesGroup::Draw(nux::GraphicsEngine& graphics_engine,
bool forceDraw)
{
nux::Geometry const& base(GetGeometry());
graphics_engine.PushClippingRectangle(base);
if (RedirectedAncestor())
graphics::ClearGeometry(GetGeometry());
if (ShouldBeHighlighted() && _focus_layer)
{
nux::Geometry geo(_header_layout->GetGeometry());
geo.width = base.width -
HIGHLIGHT_RIGHT_PADDING.CP(scale()) -
HIGHLIGHT_LEFT_PADDING.CP(scale());
geo.x += HIGHLIGHT_LEFT_PADDING.CP(scale());
_focus_layer->SetGeometry(geo);
_focus_layer->Renderlayer(graphics_engine);
}
if (_background_layer)
{
nux::Geometry bg_geo = base;
int bg_width = _background_layer->GetDeviceTexture()->GetWidth();
bg_geo.x = std::max(bg_geo.width - bg_width, 0);
// to render into a space left over by the scrollview (1 has NOT to be scaled)
bg_geo.width = std::min(bg_width, bg_geo.GetWidth()) + 1;
bg_geo.height = _background_layer->GetDeviceTexture()->GetHeight();
_background_layer->SetGeometry(bg_geo);
_background_layer->Renderlayer(graphics_engine);
}
graphics_engine.PopClippingRectangle();
}
void
PlacesGroup::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw)
{
nux::Geometry const& base = GetGeometry();
graphics_engine.PushClippingRectangle(base);
int pushed_paint_layers = 0;
if (!IsFullRedraw())
{
if (RedirectedAncestor())
{
// Bit tedious. Need to clear the area of the redirected window taken by views
if (_icon->IsRedrawNeeded())
graphics::ClearGeometry(_icon->GetGeometry());
if (_name->IsRedrawNeeded())
graphics::ClearGeometry(_name->GetGeometry());
if (_expand_label->IsRedrawNeeded())
graphics::ClearGeometry(_expand_label->GetGeometry());
if (_expand_icon->IsRedrawNeeded())
graphics::ClearGeometry(_expand_icon->GetGeometry());
if (_child_view && _child_view->IsRedrawNeeded())
graphics::ClearGeometry(_child_view->GetGeometry());
}
if (ShouldBeHighlighted() && _focus_layer)
{
++pushed_paint_layers;
nux::GetPainter().PushLayer(graphics_engine, _focus_layer->GetGeometry(), _focus_layer.get());
}
if (_background_layer)
{
++pushed_paint_layers;
nux::GetPainter().PushLayer(graphics_engine, _background_layer->GetGeometry(), _background_layer.get());
}
}
else
{
nux::GetPainter().PushPaintLayerStack();
}
_group_layout->ProcessDraw(graphics_engine, force_draw);
if (IsFullRedraw())
{
nux::GetPainter().PopPaintLayerStack();
}
else if (pushed_paint_layers > 0)
{
nux::GetPainter().PopBackground(pushed_paint_layers);
}
graphics_engine.PopClippingRectangle();
}
void
PlacesGroup::SetCounts(unsigned n_total_items)
{
_n_total_items = n_total_items;
Relayout();
}
bool
PlacesGroup::IsExpandable() const
{
return (_n_visible_items_in_unexpand_mode < _n_total_items);
}
bool
PlacesGroup::GetExpanded() const
{
return _is_expanded;
}
void
PlacesGroup::SetExpanded(bool is_expanded)
{
if (_is_expanded == is_expanded)
return;
if (is_expanded && _n_total_items <= _n_visible_items_in_unexpand_mode)
return;
_is_expanded = is_expanded;
Refresh();
if (_is_expanded)
_expand_icon->SetTexture(_style.GetGroupUnexpandIcon());
else
_expand_icon->SetTexture(_style.GetGroupExpandIcon());
auto const& tex = _expand_icon->texture();
_expand_icon->SetMinMaxSize(RawPixel(tex->GetWidth()).CP(scale), RawPixel(tex->GetHeight()).CP(scale));
expanded.emit(this);
}
void
PlacesGroup::PushExpanded()
{
_is_expanded_pushed = GetExpanded();
}
void
PlacesGroup::PopExpanded()
{
SetExpanded(_is_expanded_pushed);
}
void
PlacesGroup::RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
{
SetExpanded(!_is_expanded);
}
void
PlacesGroup::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
{
QueueDraw();
}
void
PlacesGroup::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
{
QueueDraw();
}
int
PlacesGroup::GetHeaderHeight() const
{
return _header_layout->GetGeometry().height;
}
bool PlacesGroup::HeaderHasKeyFocus() const
{
return (_header_view && _header_view->HasKeyFocus());
}
bool PlacesGroup::HeaderIsFocusable() const
{
return (_header_view != nullptr);
}
nux::View* PlacesGroup::GetHeaderFocusableView() const
{
return _header_view;
}
bool PlacesGroup::ShouldBeHighlighted() const
{
return (HeaderHasKeyFocus() && IsExpandable());
}
void PlacesGroup::SetResultsPreviewAnimationValue(float preview_animation)
{
if (_child_view)
_child_view->desaturation_progress = preview_animation;
}
void PlacesGroup::SetFiltersExpanded(bool filters_expanded)
{
nux::ROPConfig rop;
rop.Blend = true;
rop.SrcBlend = GL_ONE;
rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
nux::TexCoordXForm texxform;
if (filters_expanded && !_using_filters_background)
{
_background_layer.reset(new nux::TextureLayer(_style.GetCategoryBackground()->GetDeviceTexture(),
texxform,
nux::color::White,
false,
rop));
}
else if (!filters_expanded && _using_filters_background)
{
_background_layer.reset(new nux::TextureLayer(_style.GetCategoryBackgroundNoFilters()->GetDeviceTexture(),
texxform,
nux::color::White,
false,
rop));
}
_using_filters_background = filters_expanded;
QueueDraw();
}
//
// Key navigation
//
bool
PlacesGroup::AcceptKeyNavFocus()
{
return true;
}
//
// Introspection
//
std::string PlacesGroup::GetName() const
{
return "PlacesGroup";
}
void PlacesGroup::AddProperties(debug::IntrospectionData& wrapper)
{
wrapper.add("header-x", _header_view->GetAbsoluteX());
wrapper.add("header-y", _header_view->GetAbsoluteY());
wrapper.add("header-width", _header_view->GetAbsoluteWidth());
wrapper.add("header-height", _header_view->GetAbsoluteHeight());
wrapper.add("header-geo", _header_view->GetAbsoluteGeometry());
wrapper.add("header-has-keyfocus", HeaderHasKeyFocus());
wrapper.add("header-is-highlighted", ShouldBeHighlighted());
wrapper.add("name", _name->GetText());
wrapper.add("is-visible", IsVisible());
wrapper.add("is-expanded", GetExpanded());
wrapper.add("expand-label-is-visible", _expand_label->IsVisible());
wrapper.add("expand-label-y", _expand_label->GetAbsoluteY());
wrapper.add("expand-label-geo", _expand_label->GetAbsoluteGeometry());
wrapper.add("expand-label-baseline", _expand_label->GetBaseline());
wrapper.add("name-label-y", _name->GetAbsoluteY());
wrapper.add("name-label-baseline", _name->GetBaseline());
wrapper.add("name-label-geo", _name->GetAbsoluteGeometry());
}
glib::Variant PlacesGroup::GetCurrentFocus() const
{
if (_header_view && _header_view->HasKeyFocus())
{
return glib::Variant("HeaderView");
}
else if (_child_view && _child_view->HasKeyFocus())
{
return g_variant_new("(si)", "ResultView", _child_view->GetSelectedIndex());
}
return nullptr;
}
void PlacesGroup::SetCurrentFocus(glib::Variant const& variant)
{
if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING))
{
std::string str = glib::gchar_to_string(g_variant_get_string(variant, NULL));
if (str == "HeaderView" && _header_view)
nux::GetWindowCompositor().SetKeyFocusArea(_header_view);
}
else if (g_variant_is_of_type(variant, G_VARIANT_TYPE("(si)")))
{
glib::String str;
gint32 index;
g_variant_get(variant, "(si)", &str, &index);
if (str.Str() == "ResultView" && _child_view)
{
_child_view->SetSelectedIndex(index);
nux::GetWindowCompositor().SetKeyFocusArea(_child_view);
}
}
}
} // namespace dash
} // namespace unity
./dash/CMakeLists.txt 0000644 0000041 0000041 00000002664 13264221007 014727 0 ustar www-data www-data set(UNITY_SRC ../plugins/unityshell/src)
set (CFLAGS
${CACHED_UNITY_DEPS_CFLAGS}
${CACHED_UNITY_DEPS_CFLAGS_OTHER}
${PIC_FLAGS}
)
string (REPLACE ";" " " CFLAGS "${CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")
set (LIBS ${CACHED_UNITY_DEPS_LDFLAGS} ${UNITY_STANDALONE_LADD})
include_directories (.. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR})
add_subdirectory(previews)
#
# Headers & Sources
#
set (DASH_SOURCES
ApplicationStarterImp.cpp
DashController.cpp
DashView.cpp
DashViewPrivate.cpp
FilterAllButton.cpp
FilterBar.cpp
FilterBasicButton.cpp
FilterExpanderLabel.cpp
FilterFactory.cpp
FilterGenreButton.cpp
FilterGenreWidget.cpp
FilterMultiRangeButton.cpp
FilterMultiRangeWidget.cpp
FilterRatingsButton.cpp
FilterRatingsWidget.cpp
ScopeBar.cpp
ScopeBarIcon.cpp
ScopeView.cpp
PlacesGroup.cpp
PreviewStateMachine.cpp
ResultRenderer.cpp
ResultRendererHorizontalTile.cpp
ResultRendererTile.cpp
ResultView.cpp
ResultViewGrid.cpp
)
add_library (dash-lib STATIC ${DASH_SOURCES})
add_dependencies (dash-lib unity-core-${UNITY_API_VERSION} unity-shared)
target_link_libraries (dash-lib previews-lib)
add_pch(pch/dash_pch.hh dash-lib)
#
# Standalone variant
#
add_executable (dash StandaloneDash.cpp)
target_link_libraries (dash dash-lib unity-shared unity-shared-standalone)
./dash/ResultView.cpp 0000644 0000041 0000041 00000024516 13264221007 015004 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include "ResultView.h"
#include
#include
#include "unity-shared/IntrospectableWrappers.h"
#include "unity-shared/GraphicsUtils.h"
#include "unity-shared/UnitySettings.h"
namespace unity
{
namespace dash
{
namespace
{
double const DEFAULT_SCALE = 1.0;
}
NUX_IMPLEMENT_OBJECT_TYPE(ResultView);
ResultView::ResultView(NUX_FILE_LINE_DECL)
: View(NUX_FILE_LINE_PARAM)
, expanded(true)
, desaturation_progress(0.0)
, enable_texture_render(false)
, scale(DEFAULT_SCALE)
, renderer_(NULL)
, cached_result_(nullptr, nullptr, nullptr)
, default_click_activation_(ActivateType::PREVIEW)
{
expanded.changed.connect([this](bool value)
{
QueueRelayout();
NeedRedraw();
});
desaturation_progress.changed.connect([this](float value)
{
NeedRedraw();
});
default_click_activation.SetGetterFunction([this] {
if (Settings::Instance().double_click_activate())
return default_click_activation_;
return ActivateType::DIRECT;
});
default_click_activation.SetSetterFunction([this] (ActivateType at) {
if (default_click_activation_ != at)
{
default_click_activation_ = at;
return true;
}
return false;
});
Settings::Instance().font_scaling.changed.connect(sigc::mem_fun(this, &ResultView::UpdateFontScale));
enable_texture_render.changed.connect(sigc::mem_fun(this, &ResultView::OnEnableRenderToTexture));
scale.changed.connect(sigc::mem_fun(this, &ResultView::UpdateScale));
}
ResultView::~ResultView()
{
for( auto wrapper: introspectable_children_)
{
delete wrapper.second;
}
introspectable_children_.clear();
for (ResultIterator it(GetIteratorAtRow(0)); !it.IsLast(); ++it)
{
renderer_->Unload(*it);
}
renderer_->UnReference();
}
void ResultView::UpdateScale(double scale)
{
if (renderer_)
{
renderer_->scale = scale;
for (auto const& result : *result_model_)
renderer_->ReloadResult(result);
QueueDraw();
}
}
void ResultView::UpdateFontScale(double scale)
{
if (renderer_)
{
for (auto const& result : *result_model_)
renderer_->ReloadResult(result);
QueueDraw();
}
}
void ResultView::SetModelRenderer(ResultRenderer* renderer)
{
if (renderer_ != NULL)
renderer_->UnReference();
renderer_ = renderer;
renderer->NeedsRedraw.connect([this]()
{
NeedRedraw();
});
renderer_->SinkReference();
NeedRedraw();
}
void ResultView::AddResult(Result const& result)
{
renderer_->Preload(result);
NeedRedraw();
}
void ResultView::RemoveResult(Result const& result)
{
renderer_->Unload(result);
}
void ResultView::SetResultsModel(Results::Ptr const& result_model)
{
// cleanup
if (result_model_)
{
result_connections_.Clear();
for (ResultIterator it(GetIteratorAtRow(0)); !it.IsLast(); ++it)
RemoveResult(*it);
}
result_model_ = result_model;
if (result_model_)
{
result_connections_.Add(result_model_->result_added.connect(sigc::mem_fun(this, &ResultView::AddResult)));
result_connections_.Add(result_model_->result_removed.connect(sigc::mem_fun(this, &ResultView::RemoveResult)));
}
}
int ResultView::GetSelectedIndex() const
{
return -1;
}
void ResultView::SetSelectedIndex(int index)
{
}
unsigned ResultView::GetNumResults()
{
if (result_model_)
return result_model_->count();
return 0;
}
ResultIterator ResultView::GetIteratorAtRow(unsigned row)
{
DeeModelIter* iter = NULL;
if (result_model_)
{
if (result_model_->model())
{
iter = row > 0 ? dee_model_get_iter_at_row(result_model_->model(), row) :
dee_model_get_first_iter(result_model_->model());
return ResultIterator(result_model_->model(), iter, result_model_->GetTag());
}
}
return ResultIterator(glib::Object());
}
unsigned int ResultView::GetIndexForLocalResult(LocalResult const& local_result)
{
unsigned int index = 0;
for (ResultIterator it(GetIteratorAtRow(0)); !it.IsLast(); ++it)
{
if ((*it).uri == local_result.uri)
break;
index++;
}
return index;
}
LocalResult ResultView::GetLocalResultForIndex(unsigned int index)
{
if (index >= GetNumResults())
return LocalResult();
return LocalResult(*GetIteratorAtRow(index));
}
ResultView::ActivateType ResultView::GetLocalResultActivateType(LocalResult const& result) const
{
if (boost::starts_with(result.uri, "x-unity-no-preview"))
return ActivateType::DIRECT;
return ActivateType::PREVIEW;
}
void ResultView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
{}
void ResultView::DrawContent(nux::GraphicsEngine& GfxContent, bool force_draw)
{
nux::Geometry base = GetGeometry();
GfxContent.PushClippingRectangle(base);
if (GetCompositionLayout())
GetCompositionLayout()->ProcessDraw(GfxContent, force_draw);
GfxContent.PopClippingRectangle();
}
void ResultView::OnEnableRenderToTexture(bool enable_render_to_texture)
{
if (!enable_render_to_texture)
{
result_textures_.clear();
}
}
std::vector const& ResultView::GetResultTextureContainers()
{
UpdateRenderTextures();
return result_textures_;
}
void ResultView::RenderResultTexture(ResultViewTexture::Ptr const& result_texture)
{
// Do we need to re-create the texture?
if (!result_texture->texture.IsValid() ||
result_texture->texture->GetWidth() != GetWidth() ||
result_texture->texture->GetHeight() != GetHeight())
{
result_texture->texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(GetHeight(),
GetWidth(),
1,
nux::BITFMT_R8G8B8A8);
if (!result_texture->texture.IsValid())
return;
}
nux::GetPainter().PushBackgroundStack();
graphics::PushOffscreenRenderTarget(result_texture->texture);
// clear the texture.
CHECKGL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
CHECKGL(glClear(GL_COLOR_BUFFER_BIT));
nux::GraphicsEngine& graphics_engine(nux::GetWindowThread()->GetGraphicsEngine());
nux::Geometry offset_rect = graphics_engine.ModelViewXFormRect(GetGeometry());
graphics_engine.PushModelViewMatrix(nux::Matrix4::TRANSLATE(-offset_rect.x, -offset_rect.y, 0));
ProcessDraw(graphics_engine, true);
graphics_engine.PopModelViewMatrix();
graphics::PopOffscreenRenderTarget();
nux::GetPainter().PopBackgroundStack();
}
void ResultView::UpdateRenderTextures()
{
if (!enable_texture_render)
return;
nux::Geometry root_geo(GetAbsoluteGeometry());
if (result_textures_.size() > 0)
{
ResultViewTexture::Ptr const& result_texture = result_textures_[0];
result_texture->abs_geo.x = root_geo.x;
result_texture->abs_geo.y = root_geo.y;
result_texture->abs_geo.width = GetWidth();
result_texture->abs_geo.height = GetHeight();
}
else
{
ResultViewTexture::Ptr result_texture(new ResultViewTexture);
result_texture->abs_geo = root_geo;
result_texture->row_index = 0;
result_textures_.push_back(result_texture);
}
}
std::string ResultView::GetName() const
{
return "ResultView";
}
void ResultView::GetResultDimensions(int& rows, int& columns)
{
columns = results_per_row;
rows = result_model_ ? ceil(static_cast(result_model_->count()) / static_cast(std::max(1, columns))) : 0.0;
}
void ResultView::AddProperties(debug::IntrospectionData& introspection)
{
introspection
.add("expanded", expanded);
}
debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren()
{
// Because the children are in fact wrappers for the results, we can't just re-crate them every time the
// GetIntrospectableChildren is called; otherwise result property introspection will not work correctly (objects change each time this is called).
// Therefore, we need to be a bit more clever, and acculumate and cache the wrappers.
// clear children (no delete).
RemoveAllChildren();
std::set existing_results;
// re-create list of children.
int index = 0;
if (result_model_)
{
for (ResultIterator iter(result_model_->model()); !iter.IsLast(); ++iter)
{
Result const& result = *iter;
debug::ResultWrapper* result_wrapper = NULL;
auto map_iter = introspectable_children_.find(result.uri);
// Create new result.
if (map_iter == introspectable_children_.end())
{
result_wrapper = CreateResultWrapper(result, index);
introspectable_children_[result.uri] = result_wrapper;
}
else
{
result_wrapper = map_iter->second;
UpdateResultWrapper(result_wrapper, result, index);
}
AddChild(result_wrapper);
existing_results.insert(result.uri);
index++;
}
}
// Delete old children.
auto child_iter = introspectable_children_.begin();
for (; child_iter != introspectable_children_.end(); )
{
if (existing_results.find(child_iter->first) == existing_results.end())
{
// delete and remove the child from the map.
delete child_iter->second;
child_iter = introspectable_children_.erase(child_iter);
}
else
{
++child_iter;
}
}
return debug::Introspectable::GetIntrospectableChildren();
}
debug::ResultWrapper* ResultView::CreateResultWrapper(Result const& result, int index)
{
return new debug::ResultWrapper(result);
}
void ResultView::UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index)
{
}
}
}
./dash/FilterRatingsWidget.cpp 0000644 0000041 0000041 00000006312 13264221007 016606 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include
#include
#include "config.h"
#include
#include "unity-shared/DashStyle.h"
#include "unity-shared/GraphicsUtils.h"
#include "FilterGenreWidget.h"
#include "FilterGenreButton.h"
#include "FilterBasicButton.h"
#include "FilterRatingsButton.h"
#include "FilterRatingsWidget.h"
namespace unity
{
namespace dash
{
namespace
{
const RawPixel STAR_SIZE = 28_em;
}
NUX_IMPLEMENT_OBJECT_TYPE(FilterRatingsWidget);
FilterRatingsWidget::FilterRatingsWidget(NUX_FILE_LINE_DECL)
: FilterExpanderLabel(_("Rating"), NUX_FILE_LINE_PARAM)
, all_button_(nullptr)
{
nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
ratings_ = new FilterRatingsButton(NUX_TRACKER_LOCATION);
layout->AddView(ratings_);
UpdateSize();
SetContents(layout);
scale.changed.connect([this] (double scale) {
if (all_button_) all_button_->scale = scale;
UpdateSize();
});
}
void FilterRatingsWidget::UpdateSize()
{
dash::Style& style = dash::Style::Instance();
int top_padding = style.GetSpaceBetweenFilterWidgets().CP(scale) - style.GetFilterHighlightPadding().CP(scale) - (1_em).CP(scale); // -1 (PNGs have an 1px top padding)
int bottom_padding = style.GetFilterHighlightPadding().CP(scale);
static_cast(GetLayout())->SetTopAndBottomPadding(top_padding, bottom_padding);
ratings_->scale = scale();
ratings_->SetMinimumHeight(STAR_SIZE.CP(scale));
ratings_->ApplyMinHeight();
}
void FilterRatingsWidget::SetFilter(Filter::Ptr const& filter)
{
filter_ = std::static_pointer_cast(filter);
// all button
auto show_button_func = [this] (bool show_all_button)
{
all_button_ = show_all_button ? new FilterAllButton(NUX_TRACKER_LOCATION) : nullptr;
SetRightHandView(all_button_);
if (all_button_)
{
all_button_->scale = scale();
all_button_->SetFilter(filter_);
}
};
show_button_func(filter_->show_all_button);
filter_->show_all_button.changed.connect(show_button_func);
all_button_->SetFilter(filter_);
expanded = !filter_->collapsed();
ratings_->SetFilter(filter_);
SetLabel(filter_->name);
NeedRedraw();
}
std::string FilterRatingsWidget::GetFilterType()
{
return "FilterRatingsWidget";
}
void FilterRatingsWidget::ClearRedirectedRenderChildArea()
{
if (ratings_->IsRedrawNeeded())
graphics::ClearGeometry(ratings_->GetGeometry());
}
} // namespace dash
} // namespace unity
./dash/FilterAllButton.cpp 0000644 0000041 0000041 00000003426 13264221007 015742 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Andrea Azzarone
*
*/
#include
#include "config.h"
#include
#include "FilterAllButton.h"
namespace unity
{
namespace dash
{
NUX_IMPLEMENT_OBJECT_TYPE(FilterAllButton);
FilterAllButton::FilterAllButton(NUX_FILE_LINE_DECL)
: FilterBasicButton(_("All"), NUX_FILE_LINE_PARAM)
{
SetActive(true);
SetInputEventSensitivity(false);
state_change.connect(sigc::mem_fun(this, &FilterAllButton::OnStateChanged));
}
void FilterAllButton::SetFilter(Filter::Ptr const& filter)
{
filter_ = filter;
OnFilteringChanged(filter_->filtering); // Evil hack ;)
filtering_connection_ = filter_->filtering.changed.connect(sigc::mem_fun(this, &FilterAllButton::OnFilteringChanged));
}
void FilterAllButton::OnStateChanged(nux::View* view)
{
if (filter_ and Active())
filter_->Clear();
QueueDraw();
}
void FilterAllButton::OnFilteringChanged(bool filtering)
{
SetActive(!filtering);
SetInputEventSensitivity(filtering);
}
} // namespace dash
} // namespace unity
./dash/FilterGenreWidget.h 0000644 0000041 0000041 00000003613 13264221007 015705 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef UNITYSHELL_FILTERGENREWIDGET_H
#define UNITYSHELL_FILTERGENREWIDGET_H
#include
#include
#include
#include
#include
#include "FilterAllButton.h"
#include "FilterExpanderLabel.h"
namespace unity
{
namespace dash
{
class FilterBasicButton;
class FilterGenreButton;
class FilterGenre : public FilterExpanderLabel
{
NUX_DECLARE_OBJECT_TYPE(FilterGenre, FilterExpanderLabel);
public:
FilterGenre(int columns, NUX_FILE_LINE_PROTO);
void SetFilter(Filter::Ptr const& filter);
std::string GetFilterType();
protected:
void InitTheme();
void ClearRedirectedRenderChildArea();
private:
void OnOptionAdded(FilterOption::Ptr const& new_filter);
void OnOptionRemoved(FilterOption::Ptr const& removed_filter);
void UpdateSize(int columns);
nux::GridHLayout* genre_layout_;
FilterAllButton* all_button_;
std::vector buttons_;
CheckOptionFilter::Ptr filter_;
};
} // namespace dash
} // namespace unity
#endif // UNITYSHELL_FILTERGENRESWIDGET_H
./dash/CoverflowResultView.h 0000755 0000041 0000041 00000003025 13264221007 016333 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Jason Smith
*/
#ifndef UNITY_COVERFLOWRESULTVIEW_H
#define UNITY_COVERFLOWRESULTVIEW_H
#include "ResultView.h"
namespace unity
{
namespace dash
{
class CoverflowResultView : public ResultView
{
NUX_DECLARE_OBJECT_TYPE(CoverflowResultView, ResultView);
public:
CoverflowResultView(NUX_FILE_LINE_DECL);
~CoverflowResultView();
virtual void SetModelRenderer(ResultRenderer* renderer);
virtual void AddResult(Result& result);
virtual void RemoveResult(Result& result);
virtual void Activate(LocalResult const& local_result, int index, ActivateType type);
protected:
virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual long ComputeContentSize();
private:
struct Impl;
Impl* pimpl;
};
}
}
#endif
./dash/DashController.h 0000644 0000041 0000041 00000006171 13264221007 015260 0 ustar www-data www-data /*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Neil Jagdish Patel
*/
#ifndef UNITY_DASH_CONTROLLER_H_
#define UNITY_DASH_CONTROLLER_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include "DashView.h"
#include "unity-shared/Introspectable.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/ResizingBaseWindow.h"
namespace unity
{
namespace dash
{
class Controller : public unity::debug::Introspectable, public sigc::trackable
{
public:
typedef std::shared_ptr Ptr;
typedef std::function WindowCreator;
Controller(WindowCreator const& create_window = nullptr);
nux::BaseWindow* window() const;
bool CheckShortcutActivation(const char* key_string);
std::vector GetAllShortcuts();
nux::Property use_primary;
sigc::signal on_realize;
void HideDash();
void QuicklyHideDash();
bool ShowDash();
void ReFocusKeyInput();
bool IsVisible() const;
bool IsCommandLensOpen() const;
nux::Geometry GetInputWindowGeometry();
nux::ObjectPtr const& Dash() const;
int Monitor() const;
protected:
std::string GetName() const;
void AddProperties(debug::IntrospectionData&);
private:
void EnsureDash();
void SetupWindow();
void SetupDashView();
void RegisterUBusInterests();
nux::Geometry GetIdealWindowGeometry();
int GetIdealMonitor();
void OnMonitorChanged(int primary, std::vector const&);
void UpdateDashPosition();
void Relayout();
void OnMouseDownOutsideWindow(int x, int y, unsigned long bflags, unsigned long kflags);
void OnExternalShowDash(GVariant* variant);
void OnExternalHideDash(GVariant* variant);
void OnActivateRequest(GVariant* variant);
void FocusWindow();
void StartShowHideTimeline();
void OnViewShowHideFrame(double progress);
static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data);
private:
WindowCreator create_window_;
nux::ObjectPtr window_;
nux::ObjectPtr view_;
int monitor_;
bool visible_;
connection::Wrapper screen_ungrabbed_slot_;
connection::Wrapper form_factor_changed_;
glib::DBusServer dbus_server_;
glib::TimeoutSeconds ensure_timeout_;
glib::Source::UniquePtr grab_wait_;
nux::animation::AnimateValue timeline_animator_;
UBusManager ubus_manager_;
};
}
}
#endif
./dash/ResultRenderer.cpp 0000644 0000041 0000041 00000010342 13264221007 015630 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include "ResultRenderer.h"
#include "unity-shared/RawPixel.h"
#include
#include
#include
#include
namespace unity
{
namespace dash
{
namespace
{
const std::string DEFAULT_GICON = ". GThemedIcon text-x-preview";
const RawPixel DEFAULT_ICON_SIZE = 64_em;
GdkPixbuf* _icon_hint_get_drag_pixbuf(std::string icon_hint, int size)
{
GdkPixbuf *pbuf;
GtkIconTheme *theme;
glib::Object info;
glib::Error error;
glib::Object icon;
if (icon_hint.empty())
icon_hint = DEFAULT_GICON;
if (g_str_has_prefix(icon_hint.c_str(), "/"))
{
pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
size, size, TRUE, &error);
if (error || !pbuf || !GDK_IS_PIXBUF (pbuf))
{
icon_hint = "application-default-icon";
}
else
return pbuf;
}
theme = gtk_icon_theme_get_default();
icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
if (icon.IsType(G_TYPE_ICON))
{
if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))
{
auto anno = glib::object_cast(icon);
GIcon *base_icon = unity_protocol_annotated_icon_get_icon(anno);
info = gtk_icon_theme_lookup_by_gicon(theme, base_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);
}
else
{
info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);
}
}
else
{
info = gtk_icon_theme_lookup_icon(theme,
icon_hint.c_str(),
size,
GTK_ICON_LOOKUP_FORCE_SIZE);
}
if (!info)
{
info = gtk_icon_theme_lookup_icon(theme,
"application-default-icon",
size,
GTK_ICON_LOOKUP_FORCE_SIZE);
}
if (!gtk_icon_info_get_filename(info))
{
info = gtk_icon_theme_lookup_icon(theme,
"application-default-icon",
size,
GTK_ICON_LOOKUP_FORCE_SIZE);
}
pbuf = gtk_icon_info_load_icon(info, &error);
if (error)
{
pbuf = nullptr;
}
return pbuf;
}
double const DEFAULT_SCALE = 1.0;
}
NUX_IMPLEMENT_OBJECT_TYPE(ResultRenderer);
ResultRenderer::ResultRenderer(NUX_FILE_LINE_DECL)
: InitiallyUnownedObject(NUX_FILE_LINE_PARAM)
, width(50)
, height(50)
, scale(DEFAULT_SCALE)
{}
void ResultRenderer::Render(nux::GraphicsEngine& GfxContext,
Result& /*row*/,
ResultRendererState /*state*/,
nux::Geometry const& geometry, int /*x_offset*/, int /*y_offset*/,
nux::Color const& color,
float saturate)
{
nux::GetPainter().PushDrawSliceScaledTextureLayer(GfxContext, geometry, nux::eBUTTON_NORMAL, nux::color::White, nux::eAllCorners);
}
void ResultRenderer::Preload(Result const& row)
{
// pre-load the given row
}
void ResultRenderer::Unload(Result const& row)
{
// unload any resources
}
nux::NBitmapData* ResultRenderer::GetDndImage(Result const& row) const
{
nux::GdkGraphics graphics(_icon_hint_get_drag_pixbuf(row.icon_hint, DEFAULT_ICON_SIZE.CP(scale)));
return graphics.GetBitmap();
}
}
}
./dash/FilterBar.cpp 0000644 0000041 0000041 00000007621 13264221007 014543 0 ustar www-data www-data /*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include
#include
#include
#include "unity-shared/DashStyle.h"
#include "unity-shared/GraphicsUtils.h"
#include "FilterBar.h"
#include "FilterExpanderLabel.h"
#include "FilterFactory.h"
namespace unity
{
namespace dash
{
namespace
{
double const DEFAULT_SCALE = 1.0;
}
DECLARE_LOGGER(logger, "unity.dash.filterbar");
NUX_IMPLEMENT_OBJECT_TYPE(FilterBar);
FilterBar::FilterBar(NUX_FILE_LINE_DECL)
: View(NUX_FILE_LINE_PARAM)
, scale(DEFAULT_SCALE)
{
SetLayout(new nux::VLayout(NUX_TRACKER_LOCATION));
scale.changed.connect(sigc::mem_fun(this, &FilterBar::UpdateScale));
UpdateScale(scale);
}
void FilterBar::UpdateScale(double scale)
{
for (auto& filters : filter_map_)
filters.second->scale = scale;
auto& style = dash::Style::Instance();
auto* layout = static_cast(GetLayout());
layout->SetTopAndBottomPadding(style.GetFilterBarTopPadding().CP(scale) - style.GetFilterHighlightPadding().CP(scale));
layout->SetSpaceBetweenChildren(style.GetSpaceBetweenFilterWidgets().CP(scale) - style.GetFilterHighlightPadding().CP(scale));
}
void FilterBar::SetFilters(Filters::Ptr const& filters)
{
filters_ = filters;
}
void FilterBar::AddFilter(Filter::Ptr const& filter)
{
if (filter_map_.count(filter) > 0)
{
LOG_WARN(logger) << "Attempting to add a filter that has already been added";
return;
}
FilterExpanderLabel* filter_view = factory_.WidgetForFilter(filter);
filter_view->scale = scale();
AddChild(filter_view);
filter_map_[filter] = filter_view;
GetLayout()->AddView(filter_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
}
void FilterBar::RemoveFilter(Filter::Ptr const& filter)
{
for (auto iter: filter_map_)
{
if (iter.first->id == filter->id)
{
FilterExpanderLabel* filter_view = iter.second;
RemoveChild(filter_view);
filter_map_.erase(filter_map_.find(iter.first));
GetLayout()->RemoveChildObject(filter_view);
break;
}
}
}
void FilterBar::ClearFilters()
{
for (auto iter: filter_map_)
{
FilterExpanderLabel* filter_view = iter.second;
RemoveChild(filter_view);
GetLayout()->RemoveChildObject(filter_view);
}
filter_map_.clear();
}
void FilterBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
{}
void FilterBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw)
{
graphics_engine.PushClippingRectangle(GetGeometry());
if (!IsFullRedraw() && RedirectedAncestor())
{
for (auto iter: filter_map_)
{
FilterExpanderLabel* filter_view = iter.second;
if (filter_view && filter_view->IsVisible() && filter_view->IsRedrawNeeded())
graphics::ClearGeometry(filter_view->GetGeometry());
}
}
GetLayout()->ProcessDraw(graphics_engine, force_draw);
graphics_engine.PopClippingRectangle();
}
//
// Key navigation
//
bool FilterBar::AcceptKeyNavFocus()
{
return false;
}
//
// Introspection
//
std::string FilterBar::GetName() const
{
return "FilterBar";
}
void FilterBar::AddProperties(debug::IntrospectionData& introspection)
{
introspection.add(GetAbsoluteGeometry());
}
} // namespace dash
} // namespace unity
./dash/ResultRenderer.h 0000644 0000041 0000041 00000004300 13264221007 015272 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef RESULTRENDERER_H
#define RESULTRENDERER_H
#include
#include
namespace unity
{
namespace dash
{
class ResultRenderer : public nux::InitiallyUnownedObject
{
public:
NUX_DECLARE_OBJECT_TYPE(ResultRenderer, nux::InitiallyUnownedObject);
enum ResultRendererState
{
RESULT_RENDERER_NORMAL,
RESULT_RENDERER_ACTIVE,
RESULT_RENDERER_PRELIGHT,
RESULT_RENDERER_SELECTED,
RESULT_RENDERER_INSENSITIVE
};
ResultRenderer(NUX_FILE_LINE_PROTO);
virtual ~ResultRenderer() {}
virtual void Render(nux::GraphicsEngine& GfxContext,
Result& row,
ResultRendererState state,
nux::Geometry const& geometry,
int x_offset, int y_offset,
nux::Color const& color,
float saturate);
// this is just to start preloading images and text that the renderer might
// need - can be ignored
virtual void Preload(Result const& row);
// unload any previous grabbed images
virtual void Unload(Result const& row);
virtual void ReloadResult(Result const& row) {}
// get a image to drag
virtual nux::NBitmapData* GetDndImage(Result const& row) const;
nux::Property width;
nux::Property height;
nux::Property scale;
sigc::signal NeedsRedraw;
};
}
}
#endif // RESULTRENDERER_H
./dash/DashView.h 0000644 0000041 0000041 00000015027 13264221007 014047 0 ustar www-data www-data /*
* Copyright (C) 2010-2014 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Neil Jagdish Patel
*/
#ifndef UNITY_DASH_VIEW_H_
#define UNITY_DASH_VIEW_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include "ScopeBar.h"
#include "ScopeView.h"
#include "ApplicationStarter.h"
#include "previews/PreviewContainer.h"
#include "PreviewStateMachine.h"
#include "unity-shared/BackgroundEffectHelper.h"
#include "unity-shared/BGHash.h"
#include "unity-shared/Introspectable.h"
#include "unity-shared/OverlayRenderer.h"
#include "unity-shared/SearchBar.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/OverlayWindowButtons.h"
namespace na = nux::animation;
namespace unity
{
namespace dash
{
class DashLayout;
class DashView : public nux::View, public unity::debug::Introspectable
{
NUX_DECLARE_OBJECT_TYPE(DashView, nux::View);
typedef std::unordered_map> ScopeViews;
public:
DashView(Scopes::Ptr const& scopes, ApplicationStarter::Ptr const& application_starter);
~DashView();
nux::Property scale;
void AboutToShow();
void AboutToHide();
void Relayout();
void DisableBlur();
void OnActivateRequest(GVariant* args);
void SetMonitor(int monitor);
void SetMonitorOffset(int x, int y);
bool IsCommandLensOpen() const;
std::string const GetIdForShortcutActivation(std::string const& shortcut) const;
std::vector GetAllShortcuts();
nux::View* default_focus() const;
nux::Geometry const& GetContentGeometry() const;
protected:
void ProcessDndEnter();
virtual Area* FindKeyFocusArea(unsigned int key_symbol,
unsigned long x11_key_code,
unsigned long special_keys_state);
private:
void SetupViews();
void SetupUBusConnections();
nux::Geometry GetBestFitGeometry(nux::Geometry const& for_geo);
void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
virtual long PostLayoutManagement (long LayoutResult);
nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type);
// Dash animations
void DrawDashSplit(nux::GraphicsEngine& graphics_engine, nux::Geometry& split_clip);
void DrawPreviewContainer(nux::GraphicsEngine& graphics_engine);
void DrawPreviewResultTextures(nux::GraphicsEngine& gfx_context, bool force_draw);
void DrawPreview(nux::GraphicsEngine& gfx_context, bool force_draw);
void StartPreviewAnimation();
void EndPreviewAnimation();
void BuildPreview(Preview::Ptr model);
void ClosePreview();
void OnPreviewAnimationFinished();
void OnBackgroundColorChanged(GVariant* args);
void OnSearchChanged(std::string const& search_string);
void OnLiveSearchReached(std::string const& search_string);
void OnScopeAdded(Scope::Ptr const& scope, int position);
void OnScopeBarActivated(std::string const& id);
void OnScopeSearchFinished(std::string const& scope_id, std::string const& search_string, glib::Error const& err);
void OnResultActivated(ResultView::ActivateType type, LocalResult const& local_result, GVariant* data, std::string const& unique_id);
void OnResultActivatedReply(LocalResult const& local_result, ScopeHandledType type, glib::HintsMap const& hints);
bool DoFallbackActivation(std::string const& uri);
bool LaunchApp(std::string const& appname);
void OnEntryActivated();
std::string AnalyseScopeURI(std::string const& uri);
void UpdateScopeFilter(std::string scope_id, std::string filter, std::string value);
void UpdateScopeFilterValue(Filter::Ptr filter, std::string value);
bool AcceptKeyNavFocus();
bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
std::string GetName() const;
void AddProperties(debug::IntrospectionData&);
nux::Geometry GetRenderAbsoluteGeometry() const;
void UpdateDashViewSize();
void UpdateScale(double scale);
void OnDPIChanged();
nux::Area* KeyNavIteration(nux::KeyNavDirection direction);
nux::Area* SkipUnexpandableHeaderKeyNav();
UBusManager ubus_manager_;
Scopes::Ptr scopes_;
ScopeViews scope_views_;
ApplicationStarter::Ptr application_starter_;
// View related
PreviewStateMachine preview_state_machine_;
previews::PreviewContainer::Ptr preview_container_;
bool preview_displaying_;
std::string stored_activated_unique_id_;
dash::previews::Navigation preview_navigation_mode_;
nux::VLayout* layout_;
DashLayout* content_layout_;
nux::View* content_view_;
nux::HLayout* search_bar_layout_;
SearchBar* search_bar_;
nux::VLayout* scopes_layout_;
ScopeBar* scope_bar_;
nux::SpaceLayout* top_space_;
nux::ObjectPtr active_scope_view_;
nux::ObjectPtr preview_scope_view_;
connection::Wrapper scope_can_refine_connection_;
connection::Wrapper key_nav_focus_change_connection_;
// Drawing related
nux::Geometry content_geo_;
OverlayRenderer renderer_;
LocalResult last_activated_result_;
guint64 last_activated_timestamp_;
bool activate_on_finish_;
glib::Source::UniquePtr activate_delay_;
bool visible_;
bool neko_mode_;
nux::ObjectPtr dash_view_copy_;
nux::ObjectPtr search_view_copy_;
nux::ObjectPtr filter_view_copy_;
nux::ObjectPtr layout_copy_;
int opening_column_x_;
int opening_row_y_;
int opening_column_width_;
int opening_row_height_;
std::unique_ptr> split_animation_;
float animate_split_value_;
std::unique_ptr> preview_container_animation_;
float animate_preview_container_value_;
std::unique_ptr> preview_animation_;
float animate_preview_value_;
nux::ObjectPtr overlay_window_buttons_;
int monitor_;
friend class TestDashView;
};
}
}
#endif
./dash/ResultRendererTile.h 0000644 0000041 0000041 00000005746 13264221007 016127 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef RESULTRENDERERTILE_H
#define RESULTRENDERERTILE_H
#include "ResultRenderer.h"
#include "unity-shared/IconLoader.h"
namespace unity
{
namespace dash
{
struct TextureContainer
{
typedef nux::ObjectPtr BaseTexturePtr;
BaseTexturePtr text;
BaseTexturePtr icon;
BaseTexturePtr prelight;
glib::Object drag_icon;
int slot_handle;
TextureContainer()
: slot_handle(0)
{}
~TextureContainer()
{
if (slot_handle > 0)
IconLoader::GetDefault().DisconnectHandle(slot_handle);
}
};
class ResultRendererTile : public ResultRenderer
{
public:
NUX_DECLARE_OBJECT_TYPE(ResultRendererTile, ResultRenderer);
ResultRendererTile(NUX_FILE_LINE_PROTO, bool neko_mode = false);
virtual ~ResultRendererTile() {}
virtual void Render(nux::GraphicsEngine& GfxContext,
Result& row,
ResultRendererState state,
nux::Geometry const& geometry,
int x_offset, int y_offset,
nux::Color const& color,
float saturate);
virtual void Preload(Result const& row);
virtual void Unload(Result const& row);
virtual nux::NBitmapData* GetDndImage(Result const& row) const;
void ReloadResult(Result const& row);
int Padding() const;
protected:
virtual void LoadText(Result const& row);
void LoadIcon(Result const& row);
nux::ObjectPtr prelight_cache_;
nux::ObjectPtr normal_cache_;
private:
//icon loading callbacks
void IconLoaded(std::string const& texid, int max_width, int max_height,
glib::Object const& pixbuf,
std::string const& icon_name, Result const& row);
nux::BaseTexture* CreateTextureCallback(std::string const& texid,
int width, int height,
glib::Object const& pixbuf);
nux::BaseTexture* DrawHighlight(std::string const& texid,
int width, int height);
void UpdateWidthHeight();
bool neko_mode_;
};
}
}
#endif // RESULTRENDERERTILE_H
./dash/FilterBasicButton.h 0000644 0000041 0000041 00000004165 13264221007 015721 0 ustar www-data www-data /*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef UNITYSHELL_FILTERBASICBUTTON_H
#define UNITYSHELL_FILTERBASICBUTTON_H
#include
#include
#include
namespace unity
{
namespace dash
{
class FilterBasicButton : public nux::ToggleButton
{
NUX_DECLARE_OBJECT_TYPE(FilterBasicButton, nux::ToggleButton);
public:
FilterBasicButton(nux::TextureArea* image, NUX_FILE_LINE_PROTO);
FilterBasicButton(std::string const& label, NUX_FILE_LINE_PROTO);
FilterBasicButton(std::string const& label, nux::TextureArea* image, NUX_FILE_LINE_PROTO);
FilterBasicButton(NUX_FILE_LINE_PROTO);
nux::Property scale;
std::string const& GetLabel() const;
protected:
virtual long ComputeContentSize();
virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
void InitTheme();
void SetClearBeforeDraw(bool clear_before_draw);
void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
void RedrawFocusOverlay(nux::Geometry const& geom, cairo_t* cr);
typedef std::unique_ptr NuxCairoPtr;
NuxCairoPtr prelight_;
NuxCairoPtr active_;
NuxCairoPtr normal_;
NuxCairoPtr focus_;
nux::Geometry cached_geometry_;
private:
void UpdateScale(double);
std::string label_;
bool clear_before_draw_;
};
} // namespace dash
} // namespace unity
#endif // UNITYSHELL_FILTERBASICBUTTON_H
./dash/ResultViewGrid.cpp 0000644 0000041 0000041 00000105436 13264221007 015613 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#include
#include
#include
#include
#include
#include
#include
#include "unity-shared/IntrospectableWrappers.h"
#include "unity-shared/Timer.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/GraphicsUtils.h"
#include "unity-shared/RawPixel.h"
#include "unity-shared/WindowManager.h"
#include
#include "ResultViewGrid.h"
#include "math.h"
DECLARE_LOGGER(logger, "unity.dash.results");
namespace unity
{
namespace dash
{
namespace
{
const float UNFOCUSED_GHOST_ICON_OPACITY_REF = 0.3f;
const float UNFOCUSED_ICON_SATURATION_REF = 0.05f;
const float FOCUSED_GHOST_ICON_OPACITY_REF = 0.7f;
const float FOCUSED_ICON_SATURATION_REF = 0.5f;
const int DOUBLE_CLICK_SPEED = 500; //500 ms (double-click speed hardcoded to 400 ms in nux)
const RawPixel WIDTH_PADDING = 25_em;
const RawPixel SCROLLBAR_WIDTH = 3_em;
const std::string APPLICATION_URI_PREFIX = "application://";
}
NUX_IMPLEMENT_OBJECT_TYPE(ResultViewGrid);
ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL)
: ResultView(NUX_FILE_LINE_PARAM)
, horizontal_spacing(0)
, vertical_spacing(0)
, padding(0)
, mouse_over_index_(-1)
, active_index_(-1)
, selected_index_(-1)
, last_lazy_loaded_result_(0)
, all_results_preloaded_(true)
, last_mouse_down_x_(-1)
, last_mouse_down_y_(-1)
, drag_index_(~0)
, recorded_dash_width_(-1)
, recorded_dash_height_(-1)
, mouse_last_x_(-1)
, mouse_last_y_(-1)
, extra_horizontal_spacing_(0)
{
EnableDoubleClick(true);
SetAcceptKeyNavFocusOnMouseDown(false);
auto queue_draw_cb = sigc::hide(sigc::mem_fun(this, &ResultViewGrid::QueueDraw));
horizontal_spacing.changed.connect(queue_draw_cb);
vertical_spacing.changed.connect(queue_draw_cb);
padding.changed.connect(queue_draw_cb);
selected_index_.changed.connect(queue_draw_cb);
expanded.changed.connect([this](bool value) { if (value) all_results_preloaded_ = false; });
results_per_row.changed.connect([this](int value) { if (value > 0) all_results_preloaded_ = false; });
scale.changed.connect(sigc::mem_fun(this, &ResultViewGrid::UpdateScale));
key_nav_focus_change.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyNavFocusChange));
key_nav_focus_activate.connect([this] (nux::Area *area) {
Activate(focused_result_, selected_index_, ResultView::ActivateType::DIRECT);
});
key_down.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyDown));
mouse_move.connect(sigc::mem_fun(this, &ResultViewGrid::MouseMove));
mouse_click.connect(sigc::mem_fun(this, &ResultViewGrid::MouseClick));
mouse_double_click.connect(sigc::mem_fun(this, &ResultViewGrid::MouseDoubleClick));
mouse_down.connect([this](int x, int y, unsigned long mouse_state, unsigned long button_state)
{
last_mouse_down_x_ = x;
last_mouse_down_y_ = y;
unsigned index = GetIndexAtPosition(x, y);
mouse_over_index_ = index;
});
mouse_leave.connect([this](int x, int y, unsigned long mouse_state, unsigned long button_state)
{
mouse_over_index_ = -1;
mouse_last_x_ = -1;
mouse_last_y_ = -1;
NeedRedraw();
});
WindowManager::Default().average_color.changed.connect(queue_draw_cb);
ubus_.RegisterInterest(UBUS_DASH_SIZE_CHANGED, [this] (GVariant* data) {
// on dash size changed, we update our stored values, this sucks
//FIXME in P - make dash size the size of our dash not the entire screen
g_variant_get (data, "(ii)", &recorded_dash_width_, &recorded_dash_height_);
});
ubus_.RegisterInterest(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, [this] (GVariant* data) {
int nav_mode = 0;
GVariant* local_result_variant = NULL;
glib::String proposed_unique_id;
g_variant_get(data, "(ivs)", &nav_mode, &local_result_variant, &proposed_unique_id);
LocalResult local_result(LocalResult::FromVariant(local_result_variant));
g_variant_unref(local_result_variant);
if (proposed_unique_id.Str() != unique_id())
return;
unsigned num_results = GetNumResults();
if (local_result == activated_result_)
{
int current_index = GetIndexForLocalResult(activated_result_);
if (nav_mode == -1) // left
{
current_index--;
}
else if (nav_mode == 1) // right
{
current_index++;
}
if (current_index < 0 || static_cast(current_index) >= num_results)
{
LOG_ERROR(logger) << "requested to activated a result that does not exist: " << current_index;
return;
}
// closed
if (nav_mode == 0)
{
activated_result_.clear();
}
else
{
selected_index_ = active_index_ = current_index;
activated_result_ = GetLocalResultForIndex(current_index);
LOG_DEBUG(logger) << "activating preview for index: "
<< "(" << current_index << ")"
<< " " << activated_result_.uri;
Activate(activated_result_, current_index, ActivateType::PREVIEW);
}
}
});
SetDndEnabled(true, false);
}
void ResultViewGrid::Activate(LocalResult const& local_result, int index, ResultView::ActivateType type)
{
activate_timer_.reset();
unsigned num_results = GetNumResults();
int left_results = index;
int right_results = num_results ? (num_results - index) - 1 : 0;
//FIXME - just uses y right now, needs to use the absolute position of the bottom of the result
// (jay) Here is the fix: Compute the y position of the row where the item is located.
nux::Geometry abs_geo = GetAbsoluteGeometry();
int row_y = padding + abs_geo.y;
int column_x = padding + abs_geo.x;
int row_height = renderer_->height + vertical_spacing;
int column_width = renderer_->width + horizontal_spacing;
if (GetItemsPerRow())
{
int num_results = GetNumResults();
int items_per_row = GetItemsPerRow();
int num_row = num_results / items_per_row;
if (num_results % items_per_row)
{
++num_row;
}
int column_index = index % items_per_row;
int row_index = index / items_per_row;
column_x += column_index * column_width;
row_y += row_index * row_height;
}
if (type == ActivateType::PREVIEW)
{
if (GetLocalResultActivateType(local_result) != type)
type = ActivateType::DIRECT;
}
active_index_ = index;
guint64 timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp;
glib::Variant data(g_variant_new("(tiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results));
ResultActivated.emit(local_result, type, data);
}
void ResultViewGrid::QueueLazyLoad()
{
if (all_results_preloaded_ || GetNumResults() == 0)
return;
if (results_changed_idle_)
return;
if (!lazy_load_source_)
{
lazy_load_source_.reset(new glib::Idle(glib::Source::Priority::DEFAULT));
// dont need to reset the last start index as all the previous ones would have been preloaded already.
lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad));
}
}
void ResultViewGrid::QueueResultsChanged()
{
// even if we're not going to run the lazy load, we need to reset the start in case it's running already.
last_lazy_loaded_result_ = 0;
if (!results_changed_idle_)
{
// using glib::Source::Priority::HIGH because this needs to happen *before* next draw
results_changed_idle_.reset(new glib::Idle(glib::Source::Priority::HIGH));
results_changed_idle_->Run([this] () {
SizeReallocate();
results_changed_idle_.reset();
lazy_load_source_.reset(); // no point doing this one as well.
if (!all_results_preloaded_)
{
last_lazy_loaded_result_ = 0; // reset the lazy load index in case we got an insert
DoLazyLoad(); // also calls QueueDraw
}
return false;
});
}
}
bool ResultViewGrid::DoLazyLoad()
{
util::Timer timer;
bool queue_additional_load = false; // if this is set, we will return early and start loading more next frame
// instead we will just pre-load all the items if expanded or just one row if not
int index = 0;
int items_per_row = GetItemsPerRow();
for (ResultIterator it(GetIteratorAtRow(last_lazy_loaded_result_)); !it.IsLast(); ++it)
{
if ((!expanded && index < items_per_row) || expanded)
{
renderer_->Preload(*it);
}
if (!expanded && index >= items_per_row)
break; //early exit
if (timer.ElapsedSeconds() > 0.008)
{
queue_additional_load = true;
break;
}
last_lazy_loaded_result_++;
index++;
}
if (!queue_additional_load)
{
all_results_preloaded_ = true;
lazy_load_source_.reset();
}
else if (!lazy_load_source_)
{
lazy_load_source_.reset(new glib::Idle(glib::Source::Priority::DEFAULT));
lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad));
}
QueueDraw();
return queue_additional_load;
}
int ResultViewGrid::GetItemsPerRow()
{
int items_per_row = (GetGeometry().width - (padding * 2) + horizontal_spacing) / (renderer_->width + horizontal_spacing);
return (items_per_row) ? items_per_row : 1; // always at least one item per row
}
void ResultViewGrid::GetResultDimensions(int& rows, int& columns)
{
columns = GetItemsPerRow();
rows = result_model_ ? ceil(static_cast(result_model_->count()) / static_cast(std::max(1, columns))) : 0.0;
}
void ResultViewGrid::SetModelRenderer(ResultRenderer* renderer)
{
ResultView::SetModelRenderer(renderer);
SizeReallocate();
}
void ResultViewGrid::AddResult(Result const& result)
{
all_results_preloaded_ = false;
QueueResultsChanged();
}
void ResultViewGrid::RemoveResult(Result const& result)
{
ResultView::RemoveResult(result);
// removing a result might make a non-preloaded one visible
all_results_preloaded_ = false;
QueueResultsChanged();
}
void ResultViewGrid::SizeReallocate()
{
//FIXME - needs to use the geometry assigned to it, but only after a layout
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
int total_rows = std::ceil(num_results / (double)items_per_row) ;
int total_height = 0;
if (expanded)
{
total_height = (total_rows * renderer_->height) + (total_rows * vertical_spacing);
}
else
{
total_height = renderer_->height + vertical_spacing;
}
int width = (items_per_row * renderer_->width) + (padding*2) + ((items_per_row - 1) * horizontal_spacing);
int geo_width = GetBaseWidth();
int extra_width = geo_width - (width + WIDTH_PADDING.CP(scale()) - SCROLLBAR_WIDTH.CP(scale()));
if (items_per_row != 1)
extra_horizontal_spacing_ = extra_width / (items_per_row - 1);
if (extra_horizontal_spacing_ < 0)
extra_horizontal_spacing_ = 0;
total_height += (padding * 2); // add padding
SetMinimumHeight(total_height);
SetMaximumHeight(total_height);
mouse_over_index_ = GetIndexAtPosition(mouse_last_x_, mouse_last_y_);
results_per_row = items_per_row;
}
bool ResultViewGrid::InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character)
{
nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
switch (keysym)
{
case NUX_VK_UP:
direction = nux::KeyNavDirection::KEY_NAV_UP;
break;
case NUX_VK_DOWN:
direction = nux::KeyNavDirection::KEY_NAV_DOWN;
break;
case NUX_VK_LEFT:
direction = nux::KeyNavDirection::KEY_NAV_LEFT;
break;
case NUX_VK_RIGHT:
direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
break;
case NUX_VK_LEFT_TAB:
direction = nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS;
break;
case NUX_VK_TAB:
direction = nux::KeyNavDirection::KEY_NAV_TAB_NEXT;
break;
case NUX_VK_ENTER:
case NUX_KP_ENTER:
direction = nux::KeyNavDirection::KEY_NAV_ENTER;
break;
case XK_Menu:
return true;
default:
direction = nux::KeyNavDirection::KEY_NAV_NONE;
break;
}
if (direction == nux::KeyNavDirection::KEY_NAV_NONE
|| direction == nux::KeyNavDirection::KEY_NAV_TAB_NEXT
|| direction == nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS
|| direction == nux::KeyNavDirection::KEY_NAV_ENTER)
{
// we don't handle these cases
return false;
}
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
int total_rows = std::ceil(num_results / static_cast(items_per_row)); // items per row is always at least 1
total_rows = (expanded) ? total_rows : 1; // restrict to one row if not expanded
// check for edge cases where we want the keynav to bubble up
if (direction == nux::KEY_NAV_LEFT && (selected_index_ % items_per_row == 0))
return false; // pressed left on the first item, no diiice
else if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == static_cast(num_results - 1)))
return false; // pressed right on the last item, nope. nothing for you
else if (direction == nux::KEY_NAV_RIGHT && (selected_index_ % items_per_row) == (items_per_row - 1))
return false; // pressed right on the last item in the first row in non expanded mode. nothing doing.
else if (direction == nux::KEY_NAV_UP && selected_index_ < items_per_row)
return false; // key nav up when already on top row
else if (direction == nux::KEY_NAV_DOWN && selected_index_ >= (total_rows-1) * items_per_row)
return false; // key nav down when on bottom row
return true;
}
bool ResultViewGrid::AcceptKeyNavFocus()
{
return true;
}
void ResultViewGrid::OnKeyDown (unsigned long event_type, unsigned long event_keysym,
unsigned long event_state, const TCHAR* character,
unsigned short key_repeat_count)
{
nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
switch (event_keysym)
{
case NUX_VK_UP:
direction = nux::KeyNavDirection::KEY_NAV_UP;
break;
case NUX_VK_DOWN:
direction = nux::KeyNavDirection::KEY_NAV_DOWN;
break;
case NUX_VK_LEFT:
direction = nux::KeyNavDirection::KEY_NAV_LEFT;
break;
case NUX_VK_RIGHT:
direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
break;
case NUX_VK_LEFT_TAB:
direction = nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS;
break;
case NUX_VK_TAB:
direction = nux::KeyNavDirection::KEY_NAV_TAB_NEXT;
break;
case NUX_VK_ENTER:
case NUX_KP_ENTER:
direction = nux::KeyNavDirection::KEY_NAV_ENTER;
break;
default:
direction = nux::KeyNavDirection::KEY_NAV_NONE;
break;
}
// if we got this far, we definately got a keynav signal
if (focused_result_.uri.empty())
focused_result_ = (*GetIteratorAtRow(0));
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
int total_rows = std::ceil(num_results / static_cast(items_per_row)); // items per row is always at least 1
total_rows = (expanded) ? total_rows : 1; // restrict to one row if not expanded
if (direction == nux::KEY_NAV_LEFT && (selected_index_ == 0))
return; // pressed left on the first item, no diiice
if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == static_cast(num_results - 1)))
return; // pressed right on the last item, nope. nothing for you
if (direction == nux::KEY_NAV_RIGHT && !expanded && selected_index_ == items_per_row - 1)
return; // pressed right on the last item in the first row in non expanded mode. nothing doing.
switch (direction)
{
case (nux::KEY_NAV_LEFT):
{
selected_index_ = selected_index_ - 1;
break;
}
case (nux::KEY_NAV_RIGHT):
{
selected_index_ = selected_index_ + 1;
break;
}
case (nux::KEY_NAV_UP):
{
selected_index_ = selected_index_ - items_per_row;
break;
}
case (nux::KEY_NAV_DOWN):
{
selected_index_ = selected_index_ + items_per_row;
break;
}
default:
break;
}
selected_index_ = std::max(0, selected_index_());
selected_index_ = std::min(static_cast(num_results - 1), selected_index_());
ResultIterator iter(GetIteratorAtRow(selected_index_));
focused_result_ = (*iter);
std::tuple focused_coord = GetResultPosition(selected_index_);
int focused_x = std::get<0>(focused_coord);
int focused_y = std::get<1>(focused_coord);
ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
selection_change.emit();
if (event_type == nux::NUX_KEYDOWN && event_keysym == XK_Menu)
{
Activate(focused_result_, selected_index_, ActivateType::PREVIEW);
}
}
nux::Area* ResultViewGrid::KeyNavIteration(nux::KeyNavDirection direction)
{
return this;
}
void ResultViewGrid::OnKeyNavFocusChange(nux::Area *area, bool has_focus, nux::KeyNavDirection direction)
{
if (HasKeyFocus())
{
if (result_model_ && selected_index_ < 0 && GetNumResults())
{
ResultIterator first_iter(result_model_->model());
focused_result_ = (*first_iter);
selected_index_ = 0;
}
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
if (direction == nux::KEY_NAV_UP && expanded)
{
// This View just got focused through keyboard navigation and the
// focus is comming from the bottom. We want to focus the
// first item (on the left) of the last row in this grid.
int total_rows = std::ceil(num_results / (double)items_per_row);
selected_index_ = items_per_row * (total_rows-1);
}
if (direction != nux::KEY_NAV_NONE)
{
std::tuple focused_coord = GetResultPosition(selected_index_);
int focused_x = std::get<0>(focused_coord);
int focused_y = std::get<1>(focused_coord);
ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
}
selection_change.emit();
}
else
{
selected_index_ = -1;
focused_result_.clear();
selection_change.emit();
}
}
long ResultViewGrid::ComputeContentSize()
{
SizeReallocate();
QueueLazyLoad();
return ResultView::ComputeContentSize();
}
typedef std::tuple ResultListBounds;
ResultListBounds ResultViewGrid::GetVisableResults()
{
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
int start, end;
if (!expanded)
{
// we are not expanded, so the bounds are known
start = 0;
end = items_per_row - 1;
}
else
{
//find the row we start at
int absolute_y = GetAbsoluteY() - GetToplevel()->GetAbsoluteY();
unsigned row_size = renderer_->height + vertical_spacing;
if (absolute_y < 0)
{
// we are scrolled up a little,
int row_index = abs(absolute_y) / row_size;
start = row_index * items_per_row;
}
else
{
start = 0;
}
if (absolute_y + GetAbsoluteHeight() > GetToplevel()->GetAbsoluteHeight())
{
// our elements overflow the visable viewport
int visible_height = (GetToplevel()->GetAbsoluteHeight() - std::max(absolute_y, 0));
visible_height = std::min(visible_height, absolute_y + GetAbsoluteHeight());
int visible_rows = std::ceil(visible_height / static_cast(row_size));
end = start + (visible_rows * items_per_row) + items_per_row;
}
else
{
end = num_results - 1;
}
}
start = std::max(start, 0);
end = std::min(end, static_cast(num_results - 1));
return ResultListBounds(start, end);
}
void ResultViewGrid::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
{
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
int total_rows = (!expanded) ? 0 : (num_results / items_per_row) + 1;
int row_size = renderer_->height + vertical_spacing;
int y_position = padding + GetGeometry().y;
ResultListBounds visible_bounds = GetVisableResults();
nux::Geometry absolute_geometry(GetAbsoluteGeometry());
for (int row_index = 0; row_index <= total_rows; row_index++)
{
DrawRow(GfxContext, visible_bounds, row_index, y_position, absolute_geometry);
y_position += row_size;
}
}
void ResultViewGrid::DrawRow(nux::GraphicsEngine& GfxContext, ResultListBounds const& visible_bounds, int row_index, int y_position, nux::Geometry const& absolute_position)
{
unsigned int current_alpha_blend;
unsigned int current_src_blend_factor;
unsigned int current_dest_blend_factor;
GfxContext.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
int items_per_row = GetItemsPerRow();
int row_lower_bound = row_index * items_per_row;
if (row_lower_bound >= std::get<0>(visible_bounds) &&
row_lower_bound <= std::get<1>(visible_bounds))
{
float saturation_progress = 1.0 - desaturation_progress();
float saturation = 1.0;
float opacity = 1.0;
int x_position = padding + GetGeometry().x;
for (int column_index = 0; column_index < items_per_row; column_index++)
{
int index = (row_index * items_per_row) + column_index;
if (index < 0 || index >= (int)GetNumResults())
break;
ResultRenderer::ResultRendererState state = ResultRenderer::RESULT_RENDERER_NORMAL;
if (enable_texture_render() == false)
{
if (index == selected_index_)
{
state = ResultRenderer::RESULT_RENDERER_SELECTED;
}
}
else if (index == active_index_)
{
state = ResultRenderer::RESULT_RENDERER_SELECTED;
}
int half_width = recorded_dash_width_ / 2;
int half_height = recorded_dash_height_ / 2;
int offset_x, offset_y;
/* Guard against divide-by-zero. SIGFPEs are not mythological
* contrary to popular belief */
if (half_width >= 10)
offset_x = std::max(std::min((x_position - half_width) / (half_width / 10), 5), -5);
else
offset_x = 0;
if (half_height >= 10)
offset_y = std::max(std::min(((y_position + absolute_position.y) - half_height) / (half_height / 10), 5), -5);
else
offset_y = 0;
if (recorded_dash_width_ < 1 || recorded_dash_height_ < 1)
{
offset_x = 0;
offset_y = 0;
}
// Color and saturation
if (state == ResultRenderer::RESULT_RENDERER_SELECTED)
{
saturation = saturation_progress + (1.0-saturation_progress) * FOCUSED_ICON_SATURATION_REF;
opacity = saturation_progress + (1.0-saturation_progress) * FOCUSED_GHOST_ICON_OPACITY_REF;
}
else
{
saturation = saturation_progress + (1.0-saturation_progress) * UNFOCUSED_ICON_SATURATION_REF;
opacity = saturation_progress + (1.0-saturation_progress) * UNFOCUSED_GHOST_ICON_OPACITY_REF;
}
auto const& bg_color = WindowManager::Default().average_color();
nux::Color tint(opacity + (1.0f-opacity) * bg_color.red,
opacity + (1.0f-opacity) * bg_color.green,
opacity + (1.0f-opacity) * bg_color.blue,
opacity);
nux::Geometry render_geo(x_position, y_position, renderer_->width, renderer_->height);
Result result(*GetIteratorAtRow(index));
renderer_->Render(GfxContext,
result,
state,
render_geo,
offset_x,
offset_y,
tint,
saturation);
x_position += renderer_->width + horizontal_spacing + extra_horizontal_spacing_;
}
}
GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
}
void ResultViewGrid::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
{
nux::Geometry base = GetGeometry();
GfxContext.PushClippingRectangle(base);
if (GetCompositionLayout())
{
GetCompositionLayout()->ProcessDraw(GfxContext, force_draw);
}
GfxContext.PopClippingRectangle();
}
void ResultViewGrid::MouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
{
unsigned index = GetIndexAtPosition(x, y);
if (mouse_over_index_ != index)
{
selected_index_ = mouse_over_index_ = index;
nux::GetWindowCompositor().SetKeyFocusArea(this);
}
mouse_last_x_ = x;
mouse_last_y_ = y;
}
void ResultViewGrid::MouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
{
unsigned num_results = GetNumResults();
unsigned index = GetIndexAtPosition(x, y);
mouse_over_index_ = index;
if (index < num_results)
{
// we got a click on a button so activate it
ResultIterator it(GetIteratorAtRow(index));
Result result = *it;
selected_index_ = index;
focused_result_ = result;
activated_result_ = result;
if (nux::GetEventButton(button_flags) == nux::NUX_MOUSE_BUTTON1)
{
if (default_click_activation() == ActivateType::PREVIEW &&
GetLocalResultActivateType(activated_result_) == ActivateType::PREVIEW)
{
// delay activate for single left click. (for double click check)
activate_timer_.reset(new glib::Timeout(DOUBLE_CLICK_SPEED, [this, index] {
Activate(activated_result_, index, ActivateType::PREVIEW);
return false;
}));
}
else
{
Activate(activated_result_, index, ActivateType::DIRECT);
}
}
else
{
Activate(activated_result_, index, ActivateType::PREVIEW);
}
}
}
void ResultViewGrid::MouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
{
if (default_click_activation() == ActivateType::DIRECT)
return;
unsigned num_results = GetNumResults();
unsigned index = GetIndexAtPosition(x, y);
mouse_over_index_ = index;
if (index < num_results && nux::GetEventButton(button_flags) == nux::NUX_MOUSE_BUTTON1)
{
// we got a click on a button so activate it
ResultIterator it(GetIteratorAtRow(index));
Result result = *it;
selected_index_ = index;
focused_result_ = result;
activated_result_ = result;
Activate(activated_result_, index, ActivateType::DIRECT);
}
}
unsigned ResultViewGrid::GetIndexAtPosition(int x, int y)
{
if (x < 0 || y < 0)
return -1;
unsigned items_per_row = GetItemsPerRow();
unsigned column_size = renderer_->width + horizontal_spacing + extra_horizontal_spacing_;
unsigned row_size = renderer_->height + vertical_spacing;
int x_bound = items_per_row * column_size + padding;
if ((x < padding) || (x >= x_bound))
return -1;
if (y < padding)
return -1;
unsigned row_number = std::max((y - padding), 0) / row_size ;
unsigned column_number = std::max((x - padding), 0) / column_size;
return (row_number * items_per_row) + column_number;
}
std::tuple ResultViewGrid::GetResultPosition(LocalResult const& local_result)
{
unsigned int index = GetIndexForLocalResult(local_result);
return GetResultPosition(index);
}
std::tuple ResultViewGrid::GetResultPosition(const unsigned int& index)
{
if (G_UNLIKELY(index >= static_cast(GetNumResults()) || index < 0))
{
LOG_ERROR(logger) << "index (" << index << ") does not exist in this category";
return std::tuple(0,0);
} // out of bounds.
int items_per_row = GetItemsPerRow();
int column_size = renderer_->width + horizontal_spacing + extra_horizontal_spacing_;
int row_size = renderer_->height + vertical_spacing;
int y = row_size * (index / items_per_row) + padding;
int x = column_size * (index % items_per_row) + padding;
return std::tuple(x, y);
}
/* --------
DND code
--------
*/
bool ResultViewGrid::DndSourceDragBegin()
{
#ifdef USE_X11
drag_index_ = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_);
if (drag_index_ >= GetNumResults())
return false;
Reference();
ResultIterator iter(GetIteratorAtRow(drag_index_));
current_drag_result_ = *iter;
if (current_drag_result_.empty())
current_drag_result_.uri = current_drag_result_.uri.substr(current_drag_result_.uri.find(":") + 1);
if (boost::starts_with(current_drag_result_.uri, APPLICATION_URI_PREFIX))
{
auto desktop_id = current_drag_result_.uri.substr(APPLICATION_URI_PREFIX.size());
auto desktop_path = DesktopUtilities::GetDesktopPathById(desktop_id);
if (!desktop_path.empty())
current_drag_result_.uri = "file://" + desktop_path;
}
LOG_DEBUG (logger) << "Dnd begin at " <<
last_mouse_down_x_ << ", " << last_mouse_down_y_ << " - using; "
<< current_drag_result_.uri;
return true;
#else
return false;
#endif
}
nux::NBitmapData*
ResultViewGrid::DndSourceGetDragImage()
{
if (drag_index_ >= GetNumResults())
return nullptr;
Result result(*GetIteratorAtRow(drag_index_));
return renderer_->GetDndImage(result);
}
std::list
ResultViewGrid::DndSourceGetDragTypes()
{
std::list result;
result.push_back("text/uri-list");
return result;
}
const char* ResultViewGrid::DndSourceGetDataForType(const char* type, int* size, int* format)
{
*format = 8;
if (!current_drag_result_.empty())
{
*size = strlen(current_drag_result_.uri.c_str());
return current_drag_result_.uri.c_str();
}
else
{
*size = 0;
return 0;
}
}
void ResultViewGrid::DndSourceDragFinished(nux::DndAction result)
{
#ifdef USE_X11
UnReference();
last_mouse_down_x_ = -1;
last_mouse_down_y_ = -1;
current_drag_result_.clear();
drag_index_ = ~0;
// We need this because the drag can start in a ResultViewGrid and can
// end in another ResultViewGrid
EmitMouseLeaveSignal(0, 0, 0, 0);
// We need an extra mouse motion to highlight the icon under the mouse
// as soon as dnd finish
Display* display = nux::GetGraphicsDisplay()->GetX11Display();
if (display)
{
XWarpPointer(display, None, None, 0, 0, 0, 0, 0, 0);
XSync(display, 0);
}
#endif
}
int
ResultViewGrid::GetSelectedIndex() const
{
return selected_index_;
}
void
ResultViewGrid::SetSelectedIndex(int index)
{
unsigned num_results = GetNumResults();
if (num_results == 0)
{
focused_result_ = LocalResult();
index = -1;
}
else
{
if (index >= 0 && (unsigned)index >= num_results)
index = num_results-1;
ResultIterator iter(GetIteratorAtRow(index));
focused_result_ = (*iter);
}
selected_index_ = index;
}
void
ResultViewGrid::UpdateScale(double scale)
{
UpdateRenderTextures();
}
void
ResultViewGrid::UpdateRenderTextures()
{
nux::Geometry root_geo(GetAbsoluteGeometry());
int items_per_row = GetItemsPerRow();
unsigned num_results = GetNumResults();
unsigned int total_rows = (!expanded) ? 1 : std::ceil(num_results / (double)items_per_row);
int row_height = renderer_->height + vertical_spacing;
int cumulative_height = 0;
unsigned int row_index = 0;
for (; row_index < total_rows; row_index++)
{
// only one texture for non-expanded.
if (!expanded && row_index > 0)
break;
if (row_index >= result_textures_.size())
{
ResultViewTexture::Ptr result_texture(new ResultViewTexture);
result_texture->abs_geo.x = root_geo.x;
result_texture->abs_geo.y = root_geo.y + cumulative_height;
result_texture->abs_geo.width = GetWidth();
result_texture->abs_geo.height = row_height;
result_texture->row_index = row_index;
result_textures_.push_back(result_texture);
}
else
{
ResultViewTexture::Ptr const& result_texture(result_textures_[row_index]);
result_texture->abs_geo.x = root_geo.x;
result_texture->abs_geo.y = root_geo.y + cumulative_height;
result_texture->abs_geo.width = GetWidth();
result_texture->abs_geo.height = row_height;
result_texture->row_index = row_index;
}
cumulative_height += row_height;
}
// get rid of old textures.
for (; row_index < result_textures_.size(); row_index++)
{
result_textures_.pop_back();
}
}
void ResultViewGrid::RenderResultTexture(ResultViewTexture::Ptr const& result_texture)
{
int row_height = renderer_->height + vertical_spacing;
// Do we need to re-create the texture?
if (!result_texture->texture.IsValid() ||
result_texture->texture->GetWidth() != GetWidth() ||
result_texture->texture->GetHeight() != row_height)
{
result_texture->texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(GetWidth(),
row_height,
1,
nux::BITFMT_R8G8B8A8);
if (!result_texture->texture.IsValid())
return;
}
ResultListBounds visible_bounds(0, GetNumResults()-1);
graphics::PushOffscreenRenderTarget(result_texture->texture);
// clear the texture.
CHECKGL(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
CHECKGL(glClear(GL_COLOR_BUFFER_BIT));
nux::GraphicsEngine& graphics_engine(nux::GetWindowThread()->GetGraphicsEngine());
nux::Geometry offset_rect = graphics_engine.ModelViewXFormRect(GetGeometry());
graphics_engine.PushModelViewMatrix(nux::Matrix4::TRANSLATE(-offset_rect.x, 0, 0));
DrawRow(graphics_engine, visible_bounds, result_texture->row_index, 0, GetAbsoluteGeometry());
graphics_engine.PopModelViewMatrix();
graphics::PopOffscreenRenderTarget();
}
debug::ResultWrapper* ResultViewGrid::CreateResultWrapper(Result const& result, int index)
{
int x_offset = GetAbsoluteX();
int y_offset = GetAbsoluteY();
std::tuple result_coord = GetResultPosition(index);
nux::Geometry geo(std::get<0>(result_coord) + x_offset,
std::get<1>(result_coord) + y_offset,
renderer_->width,
renderer_->height);
return new debug::ResultWrapper(result, geo);
}
void ResultViewGrid::UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index)
{
if (!wrapper)
return;
int x_offset = GetAbsoluteX();
int y_offset = GetAbsoluteY();
std::tuple result_coord = GetResultPosition(index);
nux::Geometry geo(std::get<0>(result_coord) + x_offset,
std::get<1>(result_coord) + y_offset,
renderer_->width,
renderer_->height);
wrapper->UpdateGeometry(geo);
}
}
}
./dash/StandaloneDash.cpp 0000644 0000041 0000041 00000011055 13264221007 015555 0 ustar www-data www-data /*
* Copyright 2010 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
* Neil Jagdish Patel
*
*/
#include
#include "Nux/Nux.h"
#include "Nux/NuxTimerTickSource.h"
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include
#include
#include "ApplicationStarterImp.h"
#include "unity-shared/BGHash.h"
#include "unity-shared/FontSettings.h"
#include "DashView.h"
#include "unity-shared/UnitySettings.h"
#include "unity-shared/DashStyle.h"
#include "unity-shared/PanelStyle.h"
#include "unity-shared/ThumbnailGenerator.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/UBusWrapper.h"
#include
#include
const unity::RawPixel WIDTH(1024);
const unity::RawPixel HEIGHT(768);
using namespace unity::dash;
class TestRunner
{
public:
TestRunner(std::string const& scope, double scale)
: scope_(scope.empty() ? "home.scope" : scope)
, scale_(scale)
{}
static void InitWindowThread(nux::NThread* thread, void* InitData);
void Init();
std::string scope_;
double scale_;
nux::Layout *layout;
};
void TestRunner::Init ()
{
layout = new nux::HLayout(NUX_TRACKER_LOCATION);
DashView* view = new DashView(std::make_shared(),
std::make_shared());
view->scale = scale_;
view->DisableBlur();
view->SetMinMaxSize(WIDTH.CP(scale_), HEIGHT.CP(scale_));
layout->AddView (view, 1, nux::MINOR_POSITION_CENTER);
layout->SetMinMaxSize(WIDTH.CP(scale_), HEIGHT.CP(scale_));
view->AboutToShow();
nux::GetWindowThread()->SetLayout (layout);
nux::GetWindowCompositor().SetKeyFocusArea(view->default_focus());
unity::UBusManager::SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
g_variant_new("(sus)", scope_.c_str(), GOTO_DASH_URI, ""));
}
void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
{
TestRunner *self = (TestRunner *) InitData;
self->Init();
}
int main(int argc, char **argv)
{
gtk_init (&argc, &argv);
unity::Settings settings;
unity::BGHash bghash;
unity::FontSettings font_settings;
nux::NuxInitialize(0);
nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
// The instances for the pseudo-singletons.
unity::ThumbnailGenerator thumb_generator;
unity::dash::Style dash_style;
unity::panel::Style panel_style;
double scale = 1.0;
unity::glib::String scope;
unity::glib::Error err;
GOptionEntry args_parsed[] =
{
{ "scope", 's', 0, G_OPTION_ARG_STRING, &scope, "The default scope ", "S" },
{ "scaling-factor", 'f', 0, G_OPTION_ARG_DOUBLE, &scale, "The dash scaling factor", "F" },
{ NULL }
};
std::shared_ptr ctx(g_option_context_new("Standalone Dash"), g_option_context_free);
g_option_context_add_main_entries(ctx.get(), args_parsed, NULL);
if (!g_option_context_parse(ctx.get(), &argc, &argv, &err))
std::cerr << "Got error when parsing arguments: " << err << std::endl;
TestRunner *test_runner = new TestRunner(scope.Str(), scale);
std::unique_ptr wt(nux::CreateGUIThread(TEXT("Unity Dash"),
WIDTH.CP(scale), HEIGHT.CP(scale),
0, &TestRunner::InitWindowThread, test_runner));
nux::ObjectPtr background_tex;
background_tex.Adopt(nux::CreateTextureFromFile("/usr/share/backgrounds/warty-final-ubuntu.png"));
nux::TexCoordXForm texxform;
auto tex_layer = std::make_shared(background_tex->GetDeviceTexture(), texxform, nux::color::White);
wt->SetWindowBackgroundPaintLayer(tex_layer.get());
nux::NuxTimerTickSource tick_source;
nux::animation::AnimationController animation_controller(tick_source);
wt->Run(nullptr);
return EXIT_SUCCESS;
}
./dash/ScopeView.h 0000644 0000041 0000041 00000014414 13264221007 014240 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010-2014 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Neil Jagdish Patel
*/
#ifndef UNITY_SCOPE_VIEW_H_
#define UNITY_SCOPE_VIEW_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "FilterBar.h"
#include "unity-shared/Introspectable.h"
#include "PlacesGroup.h"
#include "ResultViewGrid.h"
#include "unity-shared/NuxObjectPtrHash.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/PlacesOverlayVScrollBar.h"
namespace unity
{
namespace dash
{
class ScopeScrollView;
class ScopeView : public nux::View, public unity::debug::Introspectable
{
NUX_DECLARE_OBJECT_TYPE(ScopeView, nux::View);
typedef std::vector CategoryGroups;
typedef std::unordered_map ResultCounts;
public:
ScopeView(Scope::Ptr const& scope, nux::Area* show_filters);
CategoryGroups GetOrderedCategoryViews() const;
FilterBar* filter_bar() const { return filter_bar_; }
Scope::Ptr scope() const;
nux::Area* fscroll_view() const;
int GetNumRows();
void AboutToShow();
void JumpToTop();
void PerformPageNavigation(ScrollDir dir);
virtual void ActivateFirst();
nux::ROProperty search_string;
nux::Property filters_expanded;
nux::Property view_type;
nux::Property can_refine_search;
nux::Property scale;
nux::Property neko_mode;
sigc::signal result_activated;
typedef std::function SearchCallback;
bool PerformSearch(std::string const& search_query, SearchCallback const& callback);
void ForceCategoryExpansion(std::string const& view_id, bool expand);
void PushFilterExpansion(bool expand);
void PopFilterExpansion();
bool GetPushedFilterExpansion() const;
void SetResultsPreviewAnimationValue(float preview_animation);
void EnableResultTextures(bool enable_result_textures);
std::vector GetResultTextureContainers();
void RenderResultTexture(ResultViewTexture::Ptr const& result_texture);
private:
void SetupViews(nux::Area* show_filters);
void SetupCategories(Categories::Ptr const& categories);
void SetupResults(Results::Ptr const& results);
void SetupFilters(Filters::Ptr const& filters);
void OnCategoryAdded(Category const& category);
void OnCategoryChanged(Category const& category);
void OnCategoryRemoved(Category const& category);
void OnResultAdded(Result const& result);
void OnResultRemoved(Result const& result);
void OnSearchComplete(std::string const& search_string, glib::HintsMap const& hints, glib::Error const& err);
void OnGroupExpanded(PlacesGroup* group);
void CheckScrollBarState();
void OnColumnsChanged();
void OnFilterAdded(Filter::Ptr filter);
void OnFilterRemoved(Filter::Ptr filter);
void OnViewTypeChanged(ScopeViewType view_type);
void OnScopeFilterExpanded(bool expanded);
void QueueReinitializeFilterCategoryModels(unsigned int index);
bool ReinitializeCategoryResultModels();
void ClearCategories();
void OnCategoryOrderChanged(std::vector const& order);
void QueueCategoryCountsCheck();
void CheckCategoryCounts();
void CheckNoResults(glib::HintsMap const& hints);
void HideResultsMessage();
void PushResultFocus(const char* reason);
void PopResultFocus(const char* reason);
ResultView* GetResultViewForCategory(unsigned int category_index);
virtual PlacesGroup::Ptr CreatePlacesGroup(Category const& category);
void BuildPreview(std::string const& uri, Preview::Ptr model);
void UpdateScopeViewSize();
void UpdateScale(double scale);
virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
virtual bool AcceptKeyNavFocus();
virtual std::string GetName() const;
virtual void AddProperties(debug::IntrospectionData&);
void OnCompositorKeyNavFocusChanged(nux::Area*, bool, nux::KeyNavDirection);
CategoryGroups category_views_;
Scope::Ptr scope_;
glib::Cancellable cancellable_;
glib::Cancellable search_cancellable_;
std::vector category_order_;
ResultCounts counts_;
bool no_results_active_;
std::string search_string_;
PlacesGroup::Ptr last_expanded_group_;
nux::HLayout* layout_;
ScopeScrollView* scroll_view_;
nux::VLayout* scroll_layout_;
ScopeScrollView* fscroll_view_;
nux::VLayout* fscroll_layout_;
FilterBar* filter_bar_;
StaticCairoText* no_results_;
UBusManager ubus_manager_;
glib::Source::UniquePtr model_updated_timeout_;
int last_good_filter_model_;
glib::Source::UniquePtr fix_filter_models_idle_;
glib::Source::UniquePtr hide_message_delay_;
bool filter_expansion_pushed_;
connection::handle result_added_connection_;
connection::handle result_removed_connection_;
connection::handle category_added_connection_;
connection::handle category_changed_connection_;
connection::handle category_removed_connection_;
connection::handle filter_added_connection_;
connection::handle filter_removed_connection_;
connection::handle key_nav_focus_connection_;
connection::Manager conn_manager_;
bool scope_connected_;
bool search_on_next_connect_;
int current_focus_category_position_;
glib::Variant current_focus_variant_;
friend class TestScopeView;
};
} // namespace dash
} // namespace unity
#endif // UNITY_SCOPE_VIEW_H_
./dash/FilterExpanderLabel.h 0000644 0000041 0000041 00000005654 13264221007 016216 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef UNITYSHELL_FILTEREXPANDERLABEL_H
#define UNITYSHELL_FILTEREXPANDERLABEL_H
#include
#include
#include
#include
#include
#include
#include
#include "unity-shared/IconTexture.h"
#include "unity-shared/Introspectable.h"
#include "unity-shared/StaticCairoText.h"
#include "unity-shared/ExpanderView.h"
namespace nux
{
class AbstractPaintLayer;
}
namespace unity
{
class HSeparator;
namespace dash
{
class FilterExpanderLabel : public nux::View, public debug::Introspectable
{
NUX_DECLARE_OBJECT_TYPE(FilterExpanderLabel, nux::View);
public:
FilterExpanderLabel(std::string const& label, NUX_FILE_LINE_PROTO);
void SetRightHandView(nux::View* view);
void SetLabel(std::string const& label);
void SetContents(nux::Layout* layout);
virtual void SetFilter(Filter::Ptr const& filter) = 0;
virtual std::string GetFilterType() = 0;
ExpanderView* expander_view() const { return expander_view_; }
nux::Property scale;
nux::Property expanded;
protected:
nux::Area* FindAreaUnderMouse(const nux::Point&, nux::NuxEventType) override;
virtual bool AcceptKeyNavFocus();
virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual void ClearRedirectedRenderChildArea() = 0;
// Introspection
virtual std::string GetName() const;
virtual void AddProperties(debug::IntrospectionData&);
private:
void BuildLayout();
void UpdateLayoutSizes();
void DoExpandChange(bool change);
bool ShouldBeHighlighted();
void UpdateScale(double scale);
nux::VLayout* layout_;
nux::LinearLayout* top_bar_layout_;
ExpanderView* expander_view_;
nux::LinearLayout* expander_layout_;
nux::View* right_hand_contents_;
StaticCairoText* cairo_label_;
nux::VLayout* arrow_layout_;
IconTexture* expand_icon_;
nux::ObjectPtr contents_;
std::unique_ptr focus_layer_;
};
} // namespace dash
} // namespace unity
#endif // UNITYSHELL_FILTEREXPANDERLABEL_H
./dash/CoverflowResultView.cpp 0000755 0000041 0000041 00000017533 13264221007 016677 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Jason Smith
*/
#include "CoverflowResultView.h"
#include "unity-shared/IconLoader.h"
#include "unity-shared/IconTexture.h"
#include "unity-shared/DashStyle.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/GraphicsUtils.h"
#include
#include
#include
#include
#include
#include
namespace unity
{
namespace dash
{
NUX_IMPLEMENT_OBJECT_TYPE(CoverflowResultView);
class CoverflowResultItem : public nux::CoverflowItem
{
public:
CoverflowResultItem(Result& result, CoverflowResultView *parent, nux::CoverflowModel::Ptr model);
virtual ~CoverflowResultItem();
nux::ObjectPtr GetTexture() const;
virtual void Activate(int button);
int Index();
std::string Uri();
Result result_;
CoverflowResultView* parent_;
nux::CoverflowModel::Ptr model_;
IconTexture *icon_texture_;
UBusManager ubus_;
};
class CoverflowResultView::Impl : public sigc::trackable
{
public:
Impl(CoverflowResultView *parent);
~Impl();
void ComputeFlatIcons();
CoverflowResultView *parent_;
nux::Coverflow *coverflow_;
nux::HLayout* layout_;
UBusManager ubus_;
};
CoverflowResultItem::CoverflowResultItem(Result& result, CoverflowResultView *parent, nux::CoverflowModel::Ptr model)
: CoverflowItem(result.name())
, result_(result)
, parent_(parent)
, model_(model)
{
Style& style = Style::Instance();
std::string const& icon_hint = result.icon_hint;
std::string icon_name = !icon_hint.empty() ? icon_hint : ". GThemedIcon text-x-preview";
static const int element_size = style.GetTileHeight();
icon_texture_ = new IconTexture(icon_name.c_str(), element_size, true);
icon_texture_->SinkReference();
icon_texture_->LoadIcon();
icon_texture_->texture_updated.connect([this] (nux::ObjectPtr const&)
{
if (parent_)
parent_->NeedRedraw();
});
}
CoverflowResultItem::~CoverflowResultItem()
{
icon_texture_->UnReference();
}
std::string CoverflowResultItem::Uri()
{
return result_.uri();
}
int CoverflowResultItem::Index()
{
int i = 0;
for (auto item : model_->Items())
{
if (this == item.GetPointer())
return i;
i++;
}
return -1;
}
nux::ObjectPtr CoverflowResultItem::GetTexture() const
{
return icon_texture_->texture();
}
void CoverflowResultItem::Activate(int button)
{
int index = Index();
int size = model_->Items().size();
glib::Variant data(g_variant_new("(iiii)", 0, 0, index, size - index));
//Left and right click take you to previews.
if (button == 1 || button == 3)
parent_->Activate(LocalResult(result_), index, ResultView::ActivateType::PREVIEW);
//Scroll click opens up music player.
else if (button == 2)
parent_->Activate(LocalResult(result_), index, ResultView::ActivateType::DIRECT);
}
CoverflowResultView::Impl::Impl(CoverflowResultView *parent)
: parent_(parent)
, coverflow_(new nux::Coverflow)
, layout_(new nux::HLayout())
{
layout_->AddView(coverflow_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
parent_->SetLayout(layout_);
coverflow_->SetCameraDistance(1.44);
coverflow_->fov = 60;
coverflow_->folding_angle = 45;
coverflow_->true_perspective = false;
coverflow_->camera_motion_drift_enabled = false;
coverflow_->show_reflection = true;
coverflow_->folding_depth = .25;
coverflow_->reflection_strength = .2f;
//coverflow_->folding_rate = 3.5;
coverflow_->kinetic_scroll_rate = 0.05f;
coverflow_->mouse_drag_rate = 1.5f;
coverflow_->pinching = 0.2f;
coverflow_->y_offset = 0.15f;
coverflow_->reflection_size = .5f;
ubus_.RegisterInterest(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, [this] (GVariant* data) {
int nav_mode = 0;
GVariant* local_result_variant = nullptr;
glib::String proposed_unique_id;
g_variant_get(data, "(ivs)", &nav_mode, &local_result_variant, &proposed_unique_id);
LocalResult local_result(LocalResult::FromVariant(local_result_variant));
g_variant_unref(local_result_variant);
if (proposed_unique_id.Str() != parent_->unique_id())
return;
unsigned num_results = coverflow_->model()->Items().size();
int current_index = parent->GetIndexForLocalResult(local_result);
if (nav_mode == -1) // left
{
current_index--;
}
else if (nav_mode == 1) // right
{
current_index++;
}
if (current_index < 0 || static_cast(current_index) >= num_results)
{
return;
}
if (nav_mode)
{
parent_->Activate(parent_->GetLocalResultForIndex(current_index), current_index, ActivateType::PREVIEW);
}
});
}
CoverflowResultView::Impl::~Impl()
{
}
CoverflowResultView::CoverflowResultView(NUX_FILE_LINE_DECL)
: ResultView(NUX_FILE_LINE_PARAM)
, pimpl(new CoverflowResultView::Impl(this))
{
Style& style = Style::Instance();
SetMinimumHeight(style.GetTileHeight());
}
CoverflowResultView::~CoverflowResultView()
{
}
void CoverflowResultView::SetModelRenderer(ResultRenderer* renderer)
{
return; // abstracting breaks down here. Needs to be reworked.
}
void CoverflowResultView::AddResult(Result& result)
{
nux::CoverflowItem::Ptr result_item(new CoverflowResultItem(result, this, pimpl->coverflow_->model()));
pimpl->coverflow_->model()->AddItem(result_item);
}
void CoverflowResultView::RemoveResult(Result& result)
{
// Ineffecient, API needs to be improved in Coverflow?
for (nux::CoverflowItem::Ptr item : pimpl->coverflow_->model()->Items())
{
CoverflowResultItem *result_item = static_cast(item.GetPointer());
if (result_item->result_.uri == result.uri) // maybe?
{
pimpl->coverflow_->model()->RemoveItem(item);
break;
}
}
}
void CoverflowResultView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
{
// do nothing here
}
void CoverflowResultView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
{
nux::Geometry base = GetGeometry();
GfxContext.PushClippingRectangle(base);
if (RedirectedAncestor())
graphics::ClearGeometry(base);
if (GetCompositionLayout())
{
GetCompositionLayout()->ProcessDraw(GfxContext, force_draw);
}
GfxContext.PopClippingRectangle();
}
void CoverflowResultView::Impl::ComputeFlatIcons()
{
float width = coverflow_->ViewportWidthAtDepth(0);
width /= coverflow_->space_between_icons();
int flat_icons = static_cast(std::floor((width - 2.0f) / 2.0f));
coverflow_->flat_icons = flat_icons;
}
long CoverflowResultView::ComputeContentSize()
{
pimpl->ComputeFlatIcons();
long ret = ResultView::ComputeContentSize();
return ret;
}
void CoverflowResultView::Activate(LocalResult const& local_result, int index, ResultView::ActivateType type)
{
unsigned num_results = pimpl->coverflow_->model()->Items().size();
int left_results = index;
int right_results = num_results ? (num_results - index) - 1 : 0;
int row_y = GetAbsoluteY();
int column_x = -1;
int row_height = renderer_->height;
int column_width = GetWidth();
glib::Variant data(g_variant_new("(iiii)", column_x, row_y, column_width, row_height, left_results, right_results));
ResultActivated.emit(local_result, type, data);
}
}
}
./dash/DashController.cpp 0000644 0000041 0000041 00000035450 13264221007 015615 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010-2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Neil Jagdish Patel
*/
#include "DashController.h"
#include
#include
#include
#include "UnityCore/GSettingsScopes.h"
#include "ApplicationStarterImp.h"
#include "unity-shared/AnimationUtils.h"
#include "unity-shared/DashStyle.h"
#include "unity-shared/PanelStyle.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/UnitySettings.h"
#include "unity-shared/UScreen.h"
#include "unity-shared/WindowManager.h"
namespace unity
{
namespace dash
{
DECLARE_LOGGER(logger, "unity.dash.controller");
const char* window_title = "unity-dash";
namespace
{
const unsigned PRELOAD_TIMEOUT_LENGTH = 40;
const unsigned FADE_DURATION = 90;
namespace dbus
{
const std::string BUS_NAME = "com.canonical.Unity";
const std::string PATH = "/com/canonical/Unity/Dash";
const std::string INTROSPECTION =\
""
" "
""
" "
" "
""
" "
"";
}
}
Controller::Controller(Controller::WindowCreator const& create_window)
: use_primary(false)
, create_window_(create_window)
, monitor_(0)
, visible_(false)
, dbus_server_(dbus::BUS_NAME)
, ensure_timeout_(PRELOAD_TIMEOUT_LENGTH)
, timeline_animator_(Settings::Instance().low_gfx() ? 0 : FADE_DURATION)
{
RegisterUBusInterests();
ensure_timeout_.Run([this]() { EnsureDash(); return false; });
timeline_animator_.updated.connect(sigc::mem_fun(this, &Controller::OnViewShowHideFrame));
// As a default. the create_window_ function should just create a base window.
if (create_window_ == nullptr)
{
create_window_ = [this]() {
return new ResizingBaseWindow(dash::window_title,
[this](nux::Geometry const& geo) {
if (view_)
return GetInputWindowGeometry();
return geo;
});
};
}
SetupWindow();
UScreen::GetDefault()->changed.connect(sigc::mem_fun(this, &Controller::OnMonitorChanged));
Settings::Instance().launcher_position.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::Relayout)));
Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) {
timeline_animator_.SetDuration(low_gfx ? 0 : FADE_DURATION);
}, *this));
form_factor_changed_ = Settings::Instance().form_factor.changed.connect([this] (FormFactor)
{
if (window_ && view_ && visible_)
{
// Relayout here so the input window size updates.
Relayout();
window_->PushToFront();
window_->SetInputFocus();
nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
}
});
auto& wm = WindowManager::Default();
wm.initiate_spread.connect(sigc::mem_fun(this, &Controller::HideDash));
wm.screen_viewport_switch_started.connect(sigc::mem_fun(this, &Controller::HideDash));
dbus_server_.AddObjects(dbus::INTROSPECTION, dbus::PATH);
dbus_server_.GetObjects().front()->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) {
if (method == "HideDash")
HideDash();
return static_cast(nullptr);
});
}
void Controller::SetupWindow()
{
window_ = create_window_();
window_->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
window_->SetConfigureNotifyCallback(&Controller::OnWindowConfigure, this);
window_->ShowWindow(false);
window_->SetOpacity(0.0f);
window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
if (nux::GetWindowThread()->IsEmbeddedWindow())
{
/* FIXME - first time we load our windows there is a race that causes the input
* window not to actually get input, this side steps that by causing an input window
* show and hide before we really need it. */
WindowManager& wm = WindowManager::Default();
wm.SaveInputFocus();
window_->EnableInputWindow(true, dash::window_title, true, false);
window_->EnableInputWindow(false, dash::window_title, true, false);
wm.RestoreInputFocus();
}
}
void Controller::SetupDashView()
{
view_ = new DashView(std::make_shared(), std::make_shared());
AddChild(view_.GetPointer());
nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);
layout->AddView(view_.GetPointer(), 1);
layout->SetContentDistribution(nux::MAJOR_POSITION_START);
layout->SetVerticalExternalMargin(0);
layout->SetHorizontalExternalMargin(0);
window_->SetLayout(layout);
window_->UpdateInputWindowGeometry();
}
void Controller::RegisterUBusInterests()
{
ubus_manager_.RegisterInterest(UBUS_DASH_EXTERNAL_ACTIVATION,
sigc::mem_fun(this, &Controller::OnExternalShowDash));
ubus_manager_.RegisterInterest(UBUS_OVERLAY_CLOSE_REQUEST,
sigc::mem_fun(this, &Controller::OnExternalHideDash));
ubus_manager_.RegisterInterest(UBUS_DASH_ABOUT_TO_SHOW,
[this] (GVariant*) { EnsureDash(); });
ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, [this] (GVariant *data)
{
unity::glib::String overlay_identity;
gboolean can_maximise = FALSE;
gint32 overlay_monitor = 0;
int width = 0;
int height = 0;
g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, &overlay_identity, &can_maximise, &overlay_monitor, &width, &height);
// hide if something else is coming up
if (overlay_identity.Str() != "dash")
{
HideDash();
}
});
}
void Controller::EnsureDash()
{
LOG_DEBUG(logger) << "Initializing Dash";
if (!window_)
SetupWindow();
if (!view_)
{
SetupDashView();
Relayout();
ensure_timeout_.Remove();
on_realize.emit();
}
}
int Controller::Monitor() const
{
return monitor_;
}
nux::BaseWindow* Controller::window() const
{
return window_.GetPointer();
}
// We update the @geo that's sent in with our desired width and height
void Controller::OnWindowConfigure(int window_width, int window_height,
nux::Geometry& geo, void* data)
{
Controller* self = static_cast(data);
geo = self->GetIdealWindowGeometry();
}
int Controller::GetIdealMonitor()
{
UScreen *uscreen = UScreen::GetDefault();
int primary_monitor;
if (window_->IsVisible())
primary_monitor = monitor_;
else if (use_primary)
primary_monitor = uscreen->GetPrimaryMonitor();
else
primary_monitor = uscreen->GetMonitorWithMouse();
return primary_monitor;
}
nux::Geometry Controller::GetIdealWindowGeometry()
{
UScreen *uscreen = UScreen::GetDefault();
auto monitor_geo = uscreen->GetMonitorGeometry(GetIdealMonitor());
int launcher_size = unity::Settings::Instance().LauncherSize(monitor_);
// We want to cover as much of the screen as possible to grab any mouse events outside
// of our window
if (Settings::Instance().launcher_position() == LauncherPosition::LEFT)
{
monitor_geo.x += launcher_size;
monitor_geo.width -= launcher_size;
}
else
{
monitor_geo.height -= launcher_size;
}
return monitor_geo;
}
void Controller::OnMonitorChanged(int primary, std::vector const& monitors)
{
if (!visible_ || !window_ || !view_)
return;
monitor_ = std::min(GetIdealMonitor(), monitors.size()-1);
view_->SetMonitor(monitor_);
Relayout();
}
void Controller::Relayout()
{
EnsureDash();
view_->Relayout();
window_->SetGeometry(GetIdealWindowGeometry());
UpdateDashPosition();
}
void Controller::UpdateDashPosition()
{
auto launcher_position = Settings::Instance().launcher_position();
int left_offset = 0;
int top_offset = panel::Style::Instance().PanelHeight(monitor_);
int launcher_size = unity::Settings::Instance().LauncherSize(monitor_);
if (launcher_position == LauncherPosition::LEFT)
{
left_offset = launcher_size;
}
else if (launcher_position == LauncherPosition::BOTTOM &&
Settings::Instance().form_factor() == FormFactor::DESKTOP)
{
auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor_);
top_offset = monitor_geo.height - view_->GetContentGeometry().height - launcher_size;
}
view_->SetMonitorOffset(left_offset, top_offset);
}
void Controller::OnMouseDownOutsideWindow(int x, int y,
unsigned long bflags, unsigned long kflags)
{
HideDash();
}
void Controller::OnExternalShowDash(GVariant* variant)
{
EnsureDash();
if (!visible_)
ShowDash();
else
HideDash();
}
void Controller::OnExternalHideDash(GVariant* variant)
{
HideDash();
}
bool Controller::ShowDash()
{
// Don't want to show at the wrong time
if (visible_)
return false;
WindowManager& wm = WindowManager::Default();
if (wm.IsExpoActive())
wm.TerminateExpo();
// We often need to wait for the mouse/keyboard to be available while a plugin
// is finishing it's animations/cleaning up. In these cases, we patiently wait
// for the screen to be available again before honouring the request.
if (wm.IsScreenGrabbed())
{
screen_ungrabbed_slot_ = wm.screen_ungrabbed.connect([this] {
grab_wait_.reset();
ShowDash();
});
// Let's wait ungrab event for maximum a couple of seconds...
grab_wait_.reset(new glib::TimeoutSeconds(2, [this] {
screen_ungrabbed_slot_->disconnect();
return false;
}));
return false;
}
screen_ungrabbed_slot_->disconnect();
wm.SaveInputFocus();
EnsureDash();
monitor_ = GetIdealMonitor();
view_->SetMonitor(monitor_);
view_->AboutToShow();
UpdateDashPosition();
FocusWindow();
visible_ = true;
StartShowHideTimeline();
nux::Geometry const& view_content_geo = view_->GetContentGeometry();
GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, monitor_, view_content_geo.width, view_content_geo.height);
ubus_manager_.SendMessage(UBUS_OVERLAY_SHOWN, info);
return true;
}
void Controller::FocusWindow()
{
window_->ShowWindow(true);
window_->PushToFront();
if (nux::GetWindowThread()->IsEmbeddedWindow())
{
// in standalone (i.e. not embedded) mode, we do not need an input window. we are one.
window_->EnableInputWindow(true, dash::window_title, true, false);
// update the input window geometry. This causes the input window to match the actual size of the dash.
window_->UpdateInputWindowGeometry();
}
window_->SetInputFocus();
window_->QueueDraw();
nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
}
void Controller::QuicklyHideDash()
{
HideDash();
timeline_animator_.Stop();
window_->ShowWindow(false);
}
void Controller::HideDash()
{
if (!visible_)
return;
EnsureDash();
view_->AboutToHide();
window_->CaptureMouseDownAnyWhereElse(false);
window_->EnableInputWindow(false, dash::window_title, true, false);
visible_ = false;
auto& wc = nux::GetWindowCompositor();
auto *key_focus_area = wc.GetKeyFocusArea();
if (key_focus_area && key_focus_area->IsChildOf(view_.GetPointer()))
wc.SetKeyFocusArea(nullptr, nux::KEY_NAV_NONE);
WindowManager::Default().RestoreInputFocus();
StartShowHideTimeline();
nux::Geometry const& view_content_geo = view_->GetContentGeometry();
GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, monitor_, view_content_geo.width, view_content_geo.height);
ubus_manager_.SendMessage(UBUS_OVERLAY_HIDDEN, info);
}
void Controller::StartShowHideTimeline()
{
EnsureDash();
animation::StartOrReverseIf(timeline_animator_, visible_);
}
void Controller::OnViewShowHideFrame(double opacity)
{
window_->SetOpacity(opacity);
if (opacity == 0.0f && !visible_)
{
window_->ShowWindow(false);
}
}
void Controller::OnActivateRequest(GVariant* variant)
{
EnsureDash();
view_->OnActivateRequest(variant);
}
bool Controller::CheckShortcutActivation(const char* key_string)
{
if (!key_string)
return false;
EnsureDash();
std::string scope_id = view_->GetIdForShortcutActivation(key_string);
if (!scope_id.empty())
{
WindowManager& wm = WindowManager::Default();
if (wm.IsScaleActive())
wm.TerminateScale();
GVariant* args = g_variant_new("(sus)", scope_id.c_str(), dash::GOTO_DASH_URI, "");
OnActivateRequest(args);
g_variant_unref(args);
return true;
}
return false;
}
std::vector Controller::GetAllShortcuts()
{
EnsureDash();
return view_->GetAllShortcuts();
}
// Introspectable
std::string Controller::GetName() const
{
return "DashController";
}
void Controller::AddProperties(debug::IntrospectionData& introspection)
{
introspection.add("visible", visible_)
.add("ideal_monitor", GetIdealMonitor())
.add("monitor", monitor_);
}
void Controller::ReFocusKeyInput()
{
if (visible_)
{
window_->PushToFront();
window_->SetInputFocus();
}
}
bool Controller::IsVisible() const
{
return visible_;
}
bool Controller::IsCommandLensOpen() const
{
return visible_ && view_->IsCommandLensOpen();
}
nux::Geometry Controller::GetInputWindowGeometry()
{
EnsureDash();
int launcher_size = Settings::Instance().LauncherSize(monitor_);
auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor_);
dash::Style& style = dash::Style::Instance();
nux::Geometry const& window_geo(window_->GetGeometry());
nux::Geometry const& view_content_geo(view_->GetContentGeometry());
nux::Geometry geo(window_geo.x, window_geo.y, view_content_geo.width, view_content_geo.height);
if (Settings::Instance().form_factor() == FormFactor::DESKTOP)
{
geo.width += style.GetDashVerticalBorderWidth().CP(view_->scale());
geo.height += style.GetDashHorizontalBorderHeight().CP(view_->scale());
if (Settings::Instance().launcher_position() == LauncherPosition::BOTTOM)
geo.y = monitor_geo.height - view_content_geo.height - launcher_size - style.GetDashHorizontalBorderHeight().CP(view_->scale());
}
else if (Settings::Instance().form_factor() == FormFactor::NETBOOK)
{
geo.height = monitor_geo.height;
if (Settings::Instance().launcher_position() == LauncherPosition::BOTTOM)
geo.height -= launcher_size;
}
return geo;
}
nux::ObjectPtr const& Controller::Dash() const
{
return view_;
}
}
}
./dash/ResultView.h 0000644 0000041 0000041 00000007660 13264221007 014452 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License version 3 along with this program. If not, see
*
*
* Authored by: Gordon Allott
*
*/
#ifndef RESULTVIEW_H
#define RESULTVIEW_H
#include
#include
#include
#include
#include
#include
#include "unity-shared/Introspectable.h"
#include "ResultRenderer.h"
namespace unity
{
namespace debug
{
class ResultWrapper;
}
namespace dash
{
struct ResultViewTexture
{
typedef std::shared_ptr Ptr;
unsigned int category_index;
nux::Geometry abs_geo;
int row_index;
nux::ObjectPtr texture;
};
class ResultView : public nux::View, public debug::Introspectable
{
public:
enum class ActivateType
{
DIRECT,
PREVIEW
};
NUX_DECLARE_OBJECT_TYPE(ResultView, nux::View);
ResultView(NUX_FILE_LINE_DECL);
virtual ~ResultView();
void SetModelRenderer(ResultRenderer* renderer);
void SetResultsModel(Results::Ptr const& results);
unsigned int GetIndexForLocalResult(LocalResult const&);
LocalResult GetLocalResultForIndex(unsigned int);
ActivateType GetLocalResultActivateType(LocalResult const&) const;
nux::Property expanded;
nux::Property results_per_row;
nux::Property unique_id;
nux::Property desaturation_progress;
nux::Property enable_texture_render;
nux::Property scale;
nux::RWProperty default_click_activation;
sigc::signal ResultActivated;
std::string GetName() const;
ResultIterator GetIteratorAtRow(unsigned row);
void AddProperties(debug::IntrospectionData&);
IntrospectableList GetIntrospectableChildren();
virtual int GetSelectedIndex() const;
virtual void SetSelectedIndex(int index);
virtual void Activate(LocalResult const& local_result, int index, ActivateType type) = 0;
std::vector const& GetResultTextureContainers();
virtual void RenderResultTexture(ResultViewTexture::Ptr const& result_texture);
virtual void GetResultDimensions(int& rows, int& columns);
protected:
virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
virtual void UpdateRenderTextures();
virtual void AddResult(Result const& result);
virtual void RemoveResult(Result const& result);
unsigned GetNumResults();
virtual debug::ResultWrapper* CreateResultWrapper(Result const& result, int index);
virtual void UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index);
void OnEnableRenderToTexture(bool enable_render_to_texture);
// properties
ResultRenderer* renderer_;
Results::Ptr result_model_;
std::map introspectable_children_;
std::vector result_textures_;
private:
void OnRowAdded(DeeModel* model, DeeModelIter* iter);
void OnRowRemoved(DeeModel* model, DeeModelIter* iter);
void UpdateScale(double scale);
void UpdateFontScale(double scale);
Result cached_result_;
ActivateType default_click_activation_;
connection::Manager result_connections_;
};
}
}
#endif //RESULTVIEW_H
./dash/pch/ 0000755 0000041 0000041 00000000000 13264221007 012731 5 ustar www-data www-data ./dash/pch/dash_pch.hh 0000644 0000041 0000041 00000002154 13264221007 015025 0 ustar www-data www-data // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see