./ 0000755 0000156 0000165 00000000000 12704153443 011100 5 ustar jenkins jenkins ./doc/ 0000755 0000156 0000165 00000000000 12704153435 011646 5 ustar jenkins jenkins ./doc/Makefile.am 0000644 0000156 0000165 00000000024 12704153435 013676 0 ustar jenkins jenkins SUBDIRS = reference
./doc/reference/ 0000755 0000156 0000165 00000000000 12704153435 013604 5 ustar jenkins jenkins ./doc/reference/Makefile.am 0000644 0000156 0000165 00000000022 12704153435 015632 0 ustar jenkins jenkins SUBDIRS = libbamf
./doc/reference/libbamf/ 0000755 0000156 0000165 00000000000 12704153435 015200 5 ustar jenkins jenkins ./doc/reference/libbamf/Makefile.am 0000644 0000156 0000165 00000002744 12704153435 017243 0 ustar jenkins jenkins ## Process this file with automake to produce Makefile.in
# automake requirements
AUTOMAKE_OPTIONS = 1.7
# The name of the module
DOC_MODULE=libbamf
# The top-level SGML file. You can change this if you want to.
DOC_MAIN_SGML_FILE = $(DOC_MODULE)-docs.sgml
# The directory containing the source code. Relative to $(srcdir).
DOC_SOURCE_DIR = ../../../lib/libbamf
# Extra options to pass to gtkdoc-scangobj. Not normally needed.
SCANGOBJ_OPTIONS =
# Extra options to supply to gtkdoc-scan.
# Fx --rebuild-types --rebuild-sections
SCAN_OPTIONS =
# Extra options to supply to gtkdoc-mkdb.
MKDB_OPTIONS = --sgml-mode --output-format=xml --ignore-files=trio
# Extra options to supply to gtkdoc-fixref. Not normally needed.
FIXXREF_OPTIONS =
# Used for dependencies. The docs will be rebuilt if any of these change.
HFILE_GLOB = $(top_srcdir)/lib/libbamf/bamf-*.h
CFILE_GLOB = $(top_srcdir)/lib/libbamf/bamf-*.c
# Images to copy into HTML directory.
HTML_IMAGES =
# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
content_files =
# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
INCLUDES= \
-I$(top_srcdir)/lib/libbamf \
$(GTK_CFLAGS) \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS)
GTKDOC_LIBS = \
$(GTK_LIBS) \
$(GLIB_LIBS) \
$(top_builddir)/lib/libbamf/libbamf$(LIBBAMF_VER).la
# This includes the standard gtk-doc make rules, copied by gtkdocize.
include $(top_srcdir)/gtk-doc.make
# Other files to distribute
# e.g. EXTRA_DIST += version.xml.in
EXTRA_DIST +=
./doc/reference/libbamf/libbamf.types 0000644 0000156 0000165 00000000226 12704153435 017662 0 ustar jenkins jenkins bamf_application_get_type
bamf_control_get_type
bamf_factory_get_type
bamf_matcher_get_type
bamf_tab_get_type
bamf_view_get_type
bamf_window_get_type
./doc/reference/libbamf/libbamf-docs.sgml 0000644 0000156 0000165 00000002055 12704153435 020410 0 ustar jenkins jenkins
]>
libbamf Reference Manual
Classes
Object Hierarchy
API Index
./autogen.sh 0000755 0000156 0000165 00000001176 12704153435 013107 0 ustar jenkins jenkins #!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
PKG_NAME="bamfdaemon"
REQUIRED_AUTOCONF_VERSION=2.59
REQUIRED_AUTOMAKE_VERSION=1.8
REQUIRED_MACROS="python.m4"
ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4"
(test -f $srcdir/configure.ac) || {
echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
echo " top-level $PKG_NAME directory"
exit 1
}
which gnome-autogen.sh || {
echo "You need to install the gnome-common module and make"
echo "sure the gnome-autogen.sh script is in your \$PATH."
exit 1
}
USE_GNOME2_MACROS=1 . gnome-autogen.sh
./plugins/ 0000755 0000156 0000165 00000000000 12704153435 012562 5 ustar jenkins jenkins ./plugins/chromium/ 0000755 0000156 0000165 00000000000 12704153435 014405 5 ustar jenkins jenkins ./plugins/chromium/_locales/ 0000755 0000156 0000165 00000000000 12704153435 016166 5 ustar jenkins jenkins ./plugins/chromium/_locales/en/ 0000755 0000156 0000165 00000000000 12704153435 016570 5 ustar jenkins jenkins ./plugins/chromium/_locales/en/messages.json 0000644 0000156 0000165 00000000133 12704153435 021267 0 ustar jenkins jenkins {
"tooltip": {
"message": "WebNow Favorite",
"description": "Tooltip Text"
}
}
./plugins/chromium/plugin/ 0000755 0000156 0000165 00000000000 12704153435 015703 5 ustar jenkins jenkins ./plugins/chromium/plugin/npupp.h 0000644 0000156 0000165 00000064216 12704153435 017227 0 ustar jenkins jenkins /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* npupp.h $Revision: 3.26 $
* function call mecahnics needed by platform specific glue code.
*/
#ifndef _NPUPP_H_
#define _NPUPP_H_
#if defined(__OS2__)
#pragma pack(1)
#endif
#ifndef GENERATINGCFM
#define GENERATINGCFM 0
#endif
#ifndef _NPAPI_H_
#ifdef __native_client__
#include
#else
#include "third_party/npapi/bindings/npapi.h"
#endif
#endif
#ifdef __native_client__
#include
#else
#include "third_party/npapi/bindings/npruntime.h"
#endif
/******************************************************************************************
plug-in function table macros
for each function in and out of the plugin API we define
typedef NPP_FooUPP
#define NewNPP_FooProc
#define CallNPP_FooProc
*******************************************************************************************/
/* NPP_Initialize */
typedef void (* NP_LOADDS NPP_InitializeUPP)(void);
#define NewNPP_InitializeProc(FUNC) \
((NPP_InitializeUPP) (FUNC))
#define CallNPP_InitializeProc(FUNC) \
(*(FUNC))()
/* NPP_Shutdown */
typedef void (* NP_LOADDS NPP_ShutdownUPP)(void);
#define NewNPP_ShutdownProc(FUNC) \
((NPP_ShutdownUPP) (FUNC))
#define CallNPP_ShutdownProc(FUNC) \
(*(FUNC))()
/* NPP_New */
typedef NPError (* NP_LOADDS NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved);
#define NewNPP_NewProc(FUNC) \
((NPP_NewUPP) (FUNC))
#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7))
/* NPP_Destroy */
typedef NPError (* NP_LOADDS NPP_DestroyUPP)(NPP instance, NPSavedData** save);
#define NewNPP_DestroyProc(FUNC) \
((NPP_DestroyUPP) (FUNC))
#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPP_SetWindow */
typedef NPError (* NP_LOADDS NPP_SetWindowUPP)(NPP instance, NPWindow* window);
#define NewNPP_SetWindowProc(FUNC) \
((NPP_SetWindowUPP) (FUNC))
#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPP_NewStream */
typedef NPError (* NP_LOADDS NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype);
#define NewNPP_NewStreamProc(FUNC) \
((NPP_NewStreamUPP) (FUNC))
#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5))
/* NPP_DestroyStream */
typedef NPError (* NP_LOADDS NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason);
#define NewNPP_DestroyStreamProc(FUNC) \
((NPP_DestroyStreamUPP) (FUNC))
#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \
(*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg))
/* NPP_WriteReady */
typedef int32_t (* NP_LOADDS NPP_WriteReadyUPP)(NPP instance, NPStream* stream);
#define NewNPP_WriteReadyProc(FUNC) \
((NPP_WriteReadyUPP) (FUNC))
#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \
(*(FUNC))((NPParg), (NPStreamPtr))
/* NPP_Write */
typedef int32_t (* NP_LOADDS NPP_WriteUPP)(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer);
#define NewNPP_WriteProc(FUNC) \
((NPP_WriteUPP) (FUNC))
#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \
(*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr))
/* NPP_StreamAsFile */
typedef void (* NP_LOADDS NPP_StreamAsFileUPP)(NPP instance, NPStream* stream, const char* fname);
#define NewNPP_StreamAsFileProc(FUNC) \
((NPP_StreamAsFileUPP) (FUNC))
#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPP_Print */
typedef void (* NP_LOADDS NPP_PrintUPP)(NPP instance, NPPrint* platformPrint);
#define NewNPP_PrintProc(FUNC) \
((NPP_PrintUPP) (FUNC))
#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \
(*(FUNC))((NPParg), (NPPrintArg))
/* NPP_HandleEvent */
typedef int16_t (* NP_LOADDS NPP_HandleEventUPP)(NPP instance, void* event);
#define NewNPP_HandleEventProc(FUNC) \
((NPP_HandleEventUPP) (FUNC))
#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \
(*(FUNC))((NPParg), (voidPtr))
/* NPP_URLNotify */
typedef void (* NP_LOADDS NPP_URLNotifyUPP)(NPP instance, const char* url, NPReason reason, void* notifyData);
#define NewNPP_URLNotifyProc(FUNC) \
((NPP_URLNotifyUPP) (FUNC))
#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPP_GetValue */
typedef NPError (* NP_LOADDS NPP_GetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue);
#define NewNPP_GetValueProc(FUNC) \
((NPP_GetValueUPP) (FUNC))
#define CallNPP_GetValueProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPP_SetValue */
typedef NPError (* NP_LOADDS NPP_SetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue);
#define NewNPP_SetValueProc(FUNC) \
((NPP_SetValueUPP) (FUNC))
#define CallNPP_SetValueProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/*
* Netscape entry points
*/
/* NPN_GetValue */
typedef NPError (* NP_LOADDS NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue);
#define NewNPN_GetValueProc(FUNC) \
((NPN_GetValueUPP) (FUNC))
#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_SetValue */
typedef NPError (* NP_LOADDS NPN_SetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue);
#define NewNPN_SetValueProc(FUNC) \
((NPN_SetValueUPP) (FUNC))
#define CallNPN_SetValueProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_GetUrlNotify */
typedef NPError (* NP_LOADDS NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData);
#define NewNPN_GetURLNotifyProc(FUNC) \
((NPN_GetURLNotifyUPP) (FUNC))
#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPN_PostUrlNotify */
typedef NPError (* NP_LOADDS NPN_PostURLNotifyUPP)(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData);
#define NewNPN_PostURLNotifyProc(FUNC) \
((NPN_PostURLNotifyUPP) (FUNC))
#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7))
/* NPN_GetUrl */
typedef NPError (* NP_LOADDS NPN_GetURLUPP)(NPP instance, const char* url, const char* window);
#define NewNPN_GetURLProc(FUNC) \
((NPN_GetURLUPP) (FUNC))
#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_PostUrl */
typedef NPError (* NP_LOADDS NPN_PostURLUPP)(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file);
#define NewNPN_PostURLProc(FUNC) \
((NPN_PostURLUPP) (FUNC))
#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6))
/* NPN_RequestRead */
typedef NPError (* NP_LOADDS NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList);
#define NewNPN_RequestReadProc(FUNC) \
((NPN_RequestReadUPP) (FUNC))
#define CallNPN_RequestReadProc(FUNC, stream, range) \
(*(FUNC))((stream), (range))
/* NPN_NewStream */
typedef NPError (* NP_LOADDS NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream);
#define NewNPN_NewStreamProc(FUNC) \
((NPN_NewStreamUPP) (FUNC))
#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \
(*(FUNC))((npp), (type), (window), (stream))
/* NPN_Write */
typedef int32_t (* NP_LOADDS NPN_WriteUPP)(NPP instance, NPStream* stream, int32_t len, void* buffer);
#define NewNPN_WriteProc(FUNC) \
((NPN_WriteUPP) (FUNC))
#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \
(*(FUNC))((npp), (stream), (len), (buffer))
/* NPN_DestroyStream */
typedef NPError (* NP_LOADDS NPN_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason);
#define NewNPN_DestroyStreamProc(FUNC) \
((NPN_DestroyStreamUPP) (FUNC))
#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \
(*(FUNC))((npp), (stream), (reason))
/* NPN_Status */
typedef void (* NP_LOADDS NPN_StatusUPP)(NPP instance, const char* message);
#define NewNPN_StatusProc(FUNC) \
((NPN_StatusUPP) (FUNC))
#define CallNPN_StatusProc(FUNC, npp, msg) \
(*(FUNC))((npp), (msg))
/* NPN_UserAgent */
typedef const char* (* NP_LOADDS NPN_UserAgentUPP)(NPP instance);
#define NewNPN_UserAgentProc(FUNC) \
((NPN_UserAgentUPP) (FUNC))
#define CallNPN_UserAgentProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_MemAlloc */
typedef void* (* NP_LOADDS NPN_MemAllocUPP)(uint32_t size);
#define NewNPN_MemAllocProc(FUNC) \
((NPN_MemAllocUPP) (FUNC))
#define CallNPN_MemAllocProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN__MemFree */
typedef void (* NP_LOADDS NPN_MemFreeUPP)(void* ptr);
#define NewNPN_MemFreeProc(FUNC) \
((NPN_MemFreeUPP) (FUNC))
#define CallNPN_MemFreeProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_MemFlush */
typedef uint32_t (* NP_LOADDS NPN_MemFlushUPP)(uint32_t size);
#define NewNPN_MemFlushProc(FUNC) \
((NPN_MemFlushUPP) (FUNC))
#define CallNPN_MemFlushProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_ReloadPlugins */
typedef void (* NP_LOADDS NPN_ReloadPluginsUPP)(NPBool reloadPages);
#define NewNPN_ReloadPluginsProc(FUNC) \
((NPN_ReloadPluginsUPP) (FUNC))
#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_GetJavaEnv */
// The return type of this used to be JRIEnv*. Use void* now to
// maintain binary compatibility but eliminate the dependency on Java
// types.
typedef void* (* NP_LOADDS NPN_GetJavaEnvUPP)(void);
#define NewNPN_GetJavaEnvProc(FUNC) \
((NPN_GetJavaEnvUPP) (FUNC))
#define CallNPN_GetJavaEnvProc(FUNC) \
(*(FUNC))()
/* NPN_GetJavaPeer */
// The return type of this used to be jref, which was a pointer to a
// Java thing. Use void* now to maintain binary compatibility but
// eliminate the dependency on Java types.
typedef void* (* NP_LOADDS NPN_GetJavaPeerUPP)(NPP instance);
#define NewNPN_GetJavaPeerProc(FUNC) \
((NPN_GetJavaPeerUPP) (FUNC))
#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_InvalidateRect */
typedef void (* NP_LOADDS NPN_InvalidateRectUPP)(NPP instance, NPRect *rect);
#define NewNPN_InvalidateRectProc(FUNC) \
((NPN_InvalidateRectUPP) (FUNC))
#define CallNPN_InvalidateRectProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPN_InvalidateRegion */
typedef void (* NP_LOADDS NPN_InvalidateRegionUPP)(NPP instance, NPRegion region);
#define NewNPN_InvalidateRegionProc(FUNC) \
((NPN_InvalidateRegionUPP) (FUNC))
#define CallNPN_InvalidateRegionProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPN_ForceRedraw */
typedef void (* NP_LOADDS NPN_ForceRedrawUPP)(NPP instance);
#define NewNPN_ForceRedrawProc(FUNC) \
((NPN_ForceRedrawUPP) (FUNC))
#define CallNPN_ForceRedrawProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_GetStringIdentifier */
typedef NPIdentifier (* NP_LOADDS NPN_GetStringIdentifierUPP)(const NPUTF8* name);
#define NewNPN_GetStringIdentifierProc(FUNC) \
((NPN_GetStringIdentifierUPP) (FUNC))
#define CallNPN_GetStringIdentifierProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_GetStringIdentifiers */
typedef void (* NP_LOADDS NPN_GetStringIdentifiersUPP)(const NPUTF8** names,
int32_t nameCount,
NPIdentifier* identifiers);
#define NewNPN_GetStringIdentifiersProc(FUNC) \
((NPN_GetStringIdentifiersUPP) (FUNC))
#define CallNPN_GetStringIdentifiersProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_GetIntIdentifier */
typedef NPIdentifier (* NP_LOADDS NPN_GetIntIdentifierUPP)(int32_t intid);
#define NewNPN_GetIntIdentifierProc(FUNC) \
((NPN_GetIntIdentifierUPP) (FUNC))
#define CallNPN_GetIntIdentifierProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_IdentifierIsString */
typedef bool (* NP_LOADDS NPN_IdentifierIsStringUPP)(NPIdentifier identifier);
#define NewNPN_IdentifierIsStringProc(FUNC) \
((NPN_IdentifierIsStringUPP) (FUNC))
#define CallNPN_IdentifierIsStringProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_UTF8FromIdentifier */
typedef NPUTF8* (* NP_LOADDS NPN_UTF8FromIdentifierUPP)(NPIdentifier identifier);
#define NewNPN_UTF8FromIdentifierProc(FUNC) \
((NPN_UTF8FromIdentifierUPP) (FUNC))
#define CallNPN_UTF8FromIdentifierProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_IntFromIdentifier */
typedef int32_t (* NP_LOADDS NPN_IntFromIdentifierUPP)(NPIdentifier identifier);
#define NewNPN_IntFromIdentifierProc(FUNC) \
((NPN_IntFromIdentifierUPP) (FUNC))
#define CallNPN_IntFromIdentifierProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_CreateObject */
typedef NPObject* (* NP_LOADDS NPN_CreateObjectUPP)(NPP npp, NPClass *aClass);
#define NewNPN_CreateObjectProc(FUNC) \
((NPN_CreateObjectUPP) (FUNC))
#define CallNPN_CreateObjectProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPN_RetainObject */
typedef NPObject* (* NP_LOADDS NPN_RetainObjectUPP)(NPObject *obj);
#define NewNPN_RetainObjectProc(FUNC) \
((NPN_RetainObjectUPP) (FUNC))
#define CallNPN_RetainObjectProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_ReleaseObject */
typedef void (* NP_LOADDS NPN_ReleaseObjectUPP)(NPObject *obj);
#define NewNPN_ReleaseObjectProc(FUNC) \
((NPN_ReleaseObjectUPP) (FUNC))
#define CallNPN_ReleaseObjectProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_Invoke */
typedef bool (* NP_LOADDS NPN_InvokeUPP)(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
#define NewNPN_InvokeProc(FUNC) \
((NPN_InvokeUPP) (FUNC))
#define CallNPN_InvokeProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6))
/* NPN_InvokeDefault */
typedef bool (* NP_LOADDS NPN_InvokeDefaultUPP)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
#define NewNPN_InvokeDefaultProc(FUNC) \
((NPN_InvokeDefaultUPP) (FUNC))
#define CallNPN_InvokeDefaultProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5))
/* NPN_Evaluate */
typedef bool (* NP_LOADDS NPN_EvaluateUPP)(NPP npp, NPObject *obj, NPString *script, NPVariant *result);
#define NewNPN_EvaluateProc(FUNC) \
((NPN_EvaluateUPP) (FUNC))
#define CallNPN_EvaluateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPN_GetProperty */
typedef bool (* NP_LOADDS NPN_GetPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
#define NewNPN_GetPropertyProc(FUNC) \
((NPN_GetPropertyUPP) (FUNC))
#define CallNPN_GetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPN_SetProperty */
typedef bool (* NP_LOADDS NPN_SetPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
#define NewNPN_SetPropertyProc(FUNC) \
((NPN_SetPropertyUPP) (FUNC))
#define CallNPN_SetPropertyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPN_RemoveProperty */
typedef bool (* NP_LOADDS NPN_RemovePropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName);
#define NewNPN_RemovePropertyProc(FUNC) \
((NPN_RemovePropertyUPP) (FUNC))
#define CallNPN_RemovePropertyProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_HasProperty */
typedef bool (* NP_LOADDS NPN_HasPropertyUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName);
#define NewNPN_HasPropertyProc(FUNC) \
((NPN_HasPropertyUPP) (FUNC))
#define CallNPN_HasPropertyProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_HasMethod */
typedef bool (* NP_LOADDS NPN_HasMethodUPP)(NPP npp, NPObject *obj, NPIdentifier propertyName);
#define NewNPN_HasMethodProc(FUNC) \
((NPN_HasMethodUPP) (FUNC))
#define CallNPN_HasMethodProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_ReleaseVariantValue */
typedef void (* NP_LOADDS NPN_ReleaseVariantValueUPP)(NPVariant *variant);
#define NewNPN_ReleaseVariantValueProc(FUNC) \
((NPN_ReleaseVariantValueUPP) (FUNC))
#define CallNPN_ReleaseVariantValueProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_SetException */
typedef void (* NP_LOADDS NPN_SetExceptionUPP)(NPObject *obj, const NPUTF8 *message);
#define NewNPN_SetExceptionProc(FUNC) \
((NPN_SetExceptionUPP) (FUNC))
#define CallNPN_SetExceptionProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPN_PushPopupsEnabledStateUPP */
typedef void (* NP_LOADDS NPN_PushPopupsEnabledStateUPP)(NPP npp, NPBool enabled);
#define NewNPN_PushPopupsEnabledStateProc(FUNC) \
((NPN_PushPopupsEnabledStateUPP) (FUNC))
#define CallNPN_PushPopupsEnabledStateProc(FUNC, ARG1, ARG2) \
(*(FUNC))((ARG1), (ARG2))
/* NPN_PopPopupsEnabledState */
typedef void (* NP_LOADDS NPN_PopPopupsEnabledStateUPP)(NPP npp);
#define NewNPN_PopPopupsEnabledStateProc(FUNC) \
((NPN_PopPopupsEnabledStateUPP) (FUNC))
#define CallNPN_PopPopupsEnabledStateProc(FUNC, ARG1) \
(*(FUNC))((ARG1))
/* NPN_Enumerate */
typedef bool (* NP_LOADDS NPN_EnumerateUPP)(NPP npp, NPObject *obj, NPIdentifier **identifier, uint32_t *count);
#define NewNPN_EnumerateProc(FUNC) \
((NPN_EnumerateUPP) (FUNC))
#define CallNPN_EnumerateProc(FUNC, ARG1, ARG2, ARG3, ARG4) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))
/* NPN_PluginThreadAsyncCall */
typedef void (* NP_LOADDS NPN_PluginThreadAsyncCallUPP)(NPP instance, void (*func)(void *), void *userData);
#define NewNPN_PluginThreadAsyncCallProc(FUNC) \
((NPN_PluginThreadAsyncCallUPP) (FUNC))
#define CallNPN_PluginThreadAsyncCallProc(FUNC, ARG1, ARG2, ARG3) \
(*(FUNC))((ARG1), (ARG2), (ARG3))
/* NPN_Construct */
typedef bool (* NP_LOADDS NPN_ConstructUPP)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
#define NewNPN_ConstructProc(FUNC) \
((NPN_ConstructUPP) (FUNC))
#define CallNPN_ConstructProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \
(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5))
/******************************************************************************************
* The actual plugin function table definitions
*******************************************************************************************/
typedef struct _NPPluginFuncs {
uint16_t size;
uint16_t version;
NPP_NewUPP newp;
NPP_DestroyUPP destroy;
NPP_SetWindowUPP setwindow;
NPP_NewStreamUPP newstream;
NPP_DestroyStreamUPP destroystream;
NPP_StreamAsFileUPP asfile;
NPP_WriteReadyUPP writeready;
NPP_WriteUPP write;
NPP_PrintUPP print;
NPP_HandleEventUPP event;
NPP_URLNotifyUPP urlnotify;
// The type of this used to be JRIGlobalRef, which was a void *.
// Use void * here directly now that we don't expose any Java
// specific things in the plugin API.
void* javaClass;
NPP_GetValueUPP getvalue;
NPP_SetValueUPP setvalue;
} NPPluginFuncs;
typedef struct _NPNetscapeFuncs {
uint16_t size;
uint16_t version;
NPN_GetURLUPP geturl;
NPN_PostURLUPP posturl;
NPN_RequestReadUPP requestread;
NPN_NewStreamUPP newstream;
NPN_WriteUPP write;
NPN_DestroyStreamUPP destroystream;
NPN_StatusUPP status;
NPN_UserAgentUPP uagent;
NPN_MemAllocUPP memalloc;
NPN_MemFreeUPP memfree;
NPN_MemFlushUPP memflush;
NPN_ReloadPluginsUPP reloadplugins;
NPN_GetJavaEnvUPP getJavaEnv;
NPN_GetJavaPeerUPP getJavaPeer;
NPN_GetURLNotifyUPP geturlnotify;
NPN_PostURLNotifyUPP posturlnotify;
NPN_GetValueUPP getvalue;
NPN_SetValueUPP setvalue;
NPN_InvalidateRectUPP invalidaterect;
NPN_InvalidateRegionUPP invalidateregion;
NPN_ForceRedrawUPP forceredraw;
NPN_GetStringIdentifierUPP getstringidentifier;
NPN_GetStringIdentifiersUPP getstringidentifiers;
NPN_GetIntIdentifierUPP getintidentifier;
NPN_IdentifierIsStringUPP identifierisstring;
NPN_UTF8FromIdentifierUPP utf8fromidentifier;
NPN_IntFromIdentifierUPP intfromidentifier;
NPN_CreateObjectUPP createobject;
NPN_RetainObjectUPP retainobject;
NPN_ReleaseObjectUPP releaseobject;
NPN_InvokeUPP invoke;
NPN_InvokeDefaultUPP invokeDefault;
NPN_EvaluateUPP evaluate;
NPN_GetPropertyUPP getproperty;
NPN_SetPropertyUPP setproperty;
NPN_RemovePropertyUPP removeproperty;
NPN_HasPropertyUPP hasproperty;
NPN_HasMethodUPP hasmethod;
NPN_ReleaseVariantValueUPP releasevariantvalue;
NPN_SetExceptionUPP setexception;
NPN_PushPopupsEnabledStateUPP pushpopupsenabledstate;
NPN_PopPopupsEnabledStateUPP poppopupsenabledstate;
NPN_EnumerateUPP enumerate;
NPN_PluginThreadAsyncCallUPP pluginthreadasynccall;
NPN_ConstructUPP construct;
} NPNetscapeFuncs;
#ifdef XP_MACOSX
/******************************************************************************************
* Mac platform-specific plugin glue stuff
*******************************************************************************************/
/*
* Main entry point of the plugin.
* This routine will be called when the plugin is loaded. The function
* tables are passed in and the plugin fills in the NPPluginFuncs table
* and NPPShutdownUPP for Netscape's use.
*/
typedef NPError (* NP_LOADDS NPP_MainEntryUPP)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownUPP*);
#define NewNPP_MainEntryProc(FUNC) \
((NPP_MainEntryUPP) (FUNC))
#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \
(*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP))
/*
* Mac OS X version(s) of NP_GetMIMEDescription(const char *)
* These can be called to retreive MIME information from the plugin dynamically
*
* Note: For compatibility with Quicktime, BPSupportedMIMEtypes is another way
* to get mime info from the plugin only on OSX and may not be supported
* in furture version -- use NP_GetMIMEDescription instead
*/
enum
{
kBPSupportedMIMETypesStructVers_1 = 1
};
typedef struct _BPSupportedMIMETypes
{
SInt32 structVersion; /* struct version */
Handle typeStrings; /* STR# formated handle, allocated by plug-in */
Handle infoStrings; /* STR# formated handle, allocated by plug-in */
} BPSupportedMIMETypes;
OSErr BP_GetSupportedMIMETypes(BPSupportedMIMETypes *mimeInfo, UInt32 flags);
/* NP_GetMIMEDescription */
#define NP_GETMIMEDESCRIPTION_NAME "NP_GetMIMEDescription"
typedef const char* (* NP_LOADDS NP_GetMIMEDescriptionUPP)();
#define NewNP_GetMIMEDescEntryProc(FUNC) \
((NP_GetMIMEDescriptionUPP) (FUNC))
#define CallNP_GetMIMEDescEntryProc(FUNC) \
(*(FUNC))()
/* BP_GetSupportedMIMETypes */
typedef OSErr (* NP_LOADDS BP_GetSupportedMIMETypesUPP)(BPSupportedMIMETypes*, UInt32);
#define NewBP_GetSupportedMIMETypesEntryProc(FUNC) \
((BP_GetSupportedMIMETypesUPP) (FUNC))
#define CallBP_GetMIMEDescEntryProc(FUNC, mimeInfo, flags) \
(*(FUNC))((mimeInfo), (flags))
#endif /* XP_MACOSX */
#if defined(_WINDOWS)
#define OSCALL WINAPI
#else
#if defined(__OS2__)
#define OSCALL _System
#else
#define OSCALL
#endif
#endif
#if defined(XP_UNIX)
/* GCC 3.3 and later support the visibility attribute. */
#if defined(__GNUC__) && \
((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
#define NP_VISIBILITY_DEFAULT __attribute__((visibility("default")))
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#define NP_VISIBILITY_DEFAULT __global
#else
#define NP_VISIBILITY_DEFAULT
#endif
#define NP_EXPORT(__type) NP_VISIBILITY_DEFAULT __type
#endif
#if defined( _WINDOWS ) || defined (__OS2__)
#ifdef __cplusplus
extern "C" {
#endif
/* plugin meta member functions */
#if defined(__OS2__)
typedef struct _NPPluginData { /* Alternate OS2 Plugin interface */
char *pMimeTypes;
char *pFileExtents;
char *pFileOpenTemplate;
char *pProductName;
char *pProductDescription;
unsigned long dwProductVersionMS;
unsigned long dwProductVersionLS;
} NPPluginData;
NPError OSCALL NP_GetPluginData(NPPluginData * pPluginData);
#endif
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs);
NPError OSCALL NP_Initialize(NPNetscapeFuncs* pFuncs);
NPError OSCALL NP_Shutdown();
char* NP_GetMIMEDescription();
#ifdef __cplusplus
}
#endif
#endif /* _WINDOWS || __OS2__ */
#if defined(__OS2__)
#pragma pack()
#endif
#ifdef XP_UNIX
#ifdef __cplusplus
extern "C" {
#endif
/* plugin meta member functions */
NP_EXPORT(char*) NP_GetPluginVersion(void);
NP_EXPORT(char*) NP_GetMIMEDescription(void);
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs*, NPPluginFuncs*);
NP_EXPORT(NPError) NP_Shutdown(void);
NP_EXPORT(NPError) NP_GetValue(void *future, NPPVariable aVariable, void *aValue);
#ifdef __cplusplus
}
#endif
#endif /* XP_UNIX */
#endif /* _NPUPP_H_ */
./plugins/chromium/plugin/npbamf.c 0000644 0000156 0000165 00000012367 12704153435 017323 0 ustar jenkins jenkins /* ***** BEGIN LICENSE BLOCK *****
* (C)opyright 2008-2009 Aplix Corporation. anselm@aplixcorp.com
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
* ***** END LICENSE BLOCK ***** */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static NPObject *so = NULL;
static NPNetscapeFuncs *npnfuncs = NULL;
static NPP inst = NULL;
/* NPN */
static void logmsg(const char *msg) {
FILE *out = fopen("npsimple.log", "a");
if(out) {
fputs(msg, out);
fclose(out);
}
}
static bool
hasMethod(NPObject* obj, NPIdentifier methodName) {
logmsg("npsimple: hasMethod\n");
return true;
}
static bool
invokeAddTab (NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
const NPString *id;
id = &NPVARIANT_TO_STRING (args[0]);
logmsg (id->UTF8Characters);
logmsg ("\n");
return true;
}
static bool
invoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
int error;
char *name;
logmsg("npsimple: invoke\n");
error = 1;
name = npnfuncs->utf8fromidentifier(methodName);
if(name && !strcmp (name, "addTab")) {
logmsg("npsimple: invoke addTab\n");
return invokeAddTab(obj, args, argCount, result);
}
npnfuncs->setexception(obj, "exception during invocation");
return false;
}
static bool
hasProperty(NPObject *obj, NPIdentifier propertyName) {
logmsg("npsimple: hasProperty\n");
return false;
}
static bool
getProperty(NPObject *obj, NPIdentifier propertyName, NPVariant *result) {
logmsg("npsimple: getProperty\n");
return false;
}
static NPClass npcRefObject = {
NP_CLASS_STRUCT_VERSION,
NULL,
NULL,
NULL,
hasMethod,
invoke,
invokeAddTab,
hasProperty,
getProperty,
NULL,
NULL,
};
/* NPP */
static NPError
nevv(NPMIMEType pluginType, NPP instance, short mode, short argc, char *argn[], char *argv[], NPSavedData *saved) {
inst = instance;
logmsg("npsimple: new\n");
return NPERR_NO_ERROR;
}
static NPError
destroy(NPP instance, NPSavedData **save) {
if(so)
npnfuncs->releaseobject(so);
so = NULL;
logmsg("npsimple: destroy\n");
return NPERR_NO_ERROR;
}
static NPError
getValue(NPP instance, NPPVariable variable, void *value) {
inst = instance;
switch(variable) {
default:
logmsg("npsimple: getvalue - default\n");
return NPERR_GENERIC_ERROR;
case NPPVpluginNameString:
logmsg("npsimple: getvalue - name string\n");
*((char **)value) = "WebFavPlugin";
break;
case NPPVpluginDescriptionString:
logmsg("npsimple: getvalue - description string\n");
*((char **)value) = "Canonical WebFav plugin.";
break;
case NPPVpluginScriptableNPObject:
logmsg("npsimple: getvalue - scriptable object\n");
if(!so)
so = npnfuncs->createobject(instance, &npcRefObject);
npnfuncs->retainobject(so);
*(NPObject **)value = so;
break;
case NPPVpluginNeedsXEmbed:
logmsg("npsimple: getvalue - xembed\n");
*((PRBool *)value) = PR_TRUE; /* for some reason returning false here results in the plugin getting shut down */
break;
}
return NPERR_NO_ERROR;
}
static NPError /* expected by Safari on Darwin */
handleEvent(NPP instance, void *ev) {
inst = instance;
logmsg("npsimple: handleEvent\n");
return NPERR_NO_ERROR;
}
static NPError /* expected by Opera */
setWindow(NPP instance, NPWindow* pNPWindow) {
inst = instance;
logmsg("npsimple: setWindow\n");
return NPERR_NO_ERROR;
}
/* EXPORT */
#ifdef __cplusplus
extern "C" {
#endif
NPError OSCALL
NP_GetEntryPoints(NPPluginFuncs *nppfuncs) {
logmsg("npsimple: NP_GetEntryPoints\n");
nppfuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
nppfuncs->newp = nevv;
nppfuncs->destroy = destroy;
nppfuncs->getvalue = getValue;
nppfuncs->event = handleEvent;
nppfuncs->setwindow = setWindow;
return NPERR_NO_ERROR;
}
#ifndef HIBYTE
#define HIBYTE(x) ((((uint32)(x)) & 0xff00) >> 8)
#endif
NPError OSCALL
NP_Initialize(NPNetscapeFuncs *npnf,
NPPluginFuncs *nppfuncs)
{
logmsg("npsimple: NP_Initialize\n");
if(npnf == NULL)
return NPERR_INVALID_FUNCTABLE_ERROR;
if(HIBYTE(npnf->version) > NP_VERSION_MAJOR)
return NPERR_INCOMPATIBLE_VERSION_ERROR;
npnfuncs = npnf;
NP_GetEntryPoints(nppfuncs);
return NPERR_NO_ERROR;
}
NPError
OSCALL NP_Shutdown() {
logmsg("npsimple: NP_Shutdown\n");
return NPERR_NO_ERROR;
}
char *
NP_GetMIMEDescription(void) {
logmsg("npsimple: NP_GetMIMEDescription\n");
return "application/x-canonical-webfav:webfav:Canonical WebFav";
}
NPError OSCALL /* needs to be present for WebKit based browsers */
NP_GetValue(void *npp, NPPVariable variable, void *value) {
inst = (NPP)npp;
return getValue((NPP)npp, variable, value);
}
#ifdef __cplusplus
}
#endif
./plugins/chromium/plugin/config.mk 0000644 0000156 0000165 00000000373 12704153435 017504 0 ustar jenkins jenkins VERSION = 0.3
# Customize below to fit your system
INCS = `pkg-config --libs --cflags libxul nspr libbamf`
CPPFLAGS = -DVERSION=\"${VERSION}\" -DXULRUNNER_SDK
CFLAGS = -g -pedantic -fPIC -Wall -O2 ${INCS} ${CPPFLAGS}
# compiler and linker
CC = gcc
./plugins/chromium/bamf.js 0000644 0000156 0000165 00000000421 12704153435 015645 0 ustar jenkins jenkins function onTabCreated (tab) {
}
function onTabRemoved (tabid) {
}
function onTabUpdated (tabid, changeInfo, tab) {
}
chrome.tabs.onUpdated.addListener (onTabUpdated);
chrome.tabs.onCreated.addListener (onTabCreated);
chrome.tabs.onRemoved.addListener (onTabRemoved);
./plugins/chromium/background.html 0000644 0000156 0000165 00000000411 12704153435 017406 0 ustar jenkins jenkins
./plugins/chromium/manifest.json 0000644 0000156 0000165 00000000417 12704153435 017110 0 ustar jenkins jenkins {
"name": "Bamf Tab Plugin",
"description": "It does stuff",
"version": "1",
"background_page": "background.html",
"permissions": [
"tabs", "http://*/*"
],
"plugins": [
{ "path": "plugin/npbamf.so", "public": false }
],
"default_locale": "en"
}
./Makefile.am.coverage 0000644 0000156 0000165 00000002575 12704153435 014740 0 ustar jenkins jenkins
# Coverage targets
.PHONY: clean-gcno clean-gcda \
coverage-html generate-coverage-html clean-coverage-html \
coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
clean-gcno:
@echo Removing old coverage instrumentation
-find -name '*.gcno' -print | xargs -r rm
clean-gcda:
@echo Removing old coverage results
-find -name '*.gcda' -print | xargs -r rm
if HAVE_GCOV
coverage-html:
-$(MAKE) $(AM_MAKEFLAGS) -k check
$(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
generate-coverage-html:
@echo Collecting coverage data
$(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
clean-coverage-html: clean-gcda
-$(LCOV) --directory $(top_builddir) -z
-rm -rf coverage.info coveragereport
if HAVE_GCOVR
coverage-gcovr:
-$(MAKE) $(AM_MAKEFLAGS) -k check
$(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
coverage-xml: coverage-gcovr
generate-coverage-gcovr:
@echo Generating coverage GCOVR report
$(GCOVR) --xml -r $(top_builddir) -e "tests.*" -o $(top_builddir)/coverage.xml
endif # HAVE_GCOVR
endif # HAVE_GCOV
clean-coverage-gcovr: clean-gcda
-rm -f $(top_builddir)/coverage.xml
clean-coverage-xml: clean-coverage-gcovr
./tests/ 0000755 0000156 0000165 00000000000 12704153435 012243 5 ustar jenkins jenkins ./tests/Makefile.am.gtests 0000644 0000156 0000165 00000003324 12704153435 015611 0 ustar jenkins jenkins # Utility targets for testing. The variable $(TEST_BINARY) defines the binary
# to be ran to perform the gtests.
#
# Author: Marco Trevisan
GTESTER2XUNIT_RUN = $(abs_top_srcdir)/tests/gtester2xunit.py
# Run tests as part of make check
if ENABLE_HEADLESS_TESTS
XVFB_RUN = $(abs_top_srcdir)/tests/run-xvfb.sh
LOG_PATH = headless-logs
test-headless:
set -e; \
rm -rf $(LOG_PATH); \
mkdir $(LOG_PATH); \
export LOG_PATH=$(LOG_PATH); \
export XVFB_PATH=$(XVFB); \
export DISPLAY=""; \
export XDG_CURRENT_DESKTOP="Unity"; \
source $(XVFB_RUN); \
\
$(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \
source $(LOG_PATH)/sessionbus.sh; \
\
make $(AM_MAKEFLAGS) -k test;
\
source $(LOG_PATH)/sessionbus.sh; \
rm $(LOG_PATH)/sessionbus.sh; \
kill $$DBUS_SESSION_BUS_PID;
check-local: test-headless
else # END HEADLESS TESTS
check-local: test
endif
test:
@gtester -k --verbose -o=$(TEST_BINARY)-results.xml ./$(TEST_BINARY); \
$(GTESTER2XUNIT_RUN) -x $(abs_top_srcdir)/tests/gtester.xsl $(TEST_BINARY)-results.xml
.PHONY: check-report full-report
check-report: $(TEST_BINARY)
@gtester -k --verbose -o=$(TEST_BINARY)-results.xml -k ./$(TEST_BINARY) \
&& ( gtester-report $(TEST_BINARY)-results.xml \
| sed 's/GTester Unit Test Report>GTester Unit Test Report (normal)' \
> $(TEST_BINARY)-results.html ) \
&& gnome-open ./$(TEST_BINARY)-results.html
full-report:
@gtester -k --verbose -o=$(TEST_BINARY)-results.xml -k -m=slow ./$(TEST_BINARY) \
&& ( gtester-report $(TEST_BINARY)-results.xml \
| sed 's/>GTester Unit Test Report>GTester Unit Test Report (normal)' \
> $(TEST_BINARY)-results.html )
clean-generic:
rm -f $(TEST_BINARY)-results*.xml $(TEST_BINARY)-results.html
./tests/run-xvfb.sh 0000755 0000156 0000165 00000001122 12704153435 014345 0 ustar jenkins jenkins # This script is based on the one used on dbusmenu project
if [ -z "$DISPLAY" ] && [ -x "$XVFB_PATH" ]; then
if [ -n "$LOG_PATH" ]; then
xvfb_log=$LOG_PATH/Xvfb.out
else
xvfb_log=/dev/null
fi
XID=`for id in $(seq 100 150); do test -e /tmp/.X$id-lock || { echo $id; exit 0; }; done; exit 1`
{ $XVFB_PATH :$XID -ac -noreset -screen 0 800x600x16 -nolisten tcp -auth /dev/null > $xvfb_log 2>&1 & trap "kill -15 $! || true" 0 HUP INT QUIT TRAP USR1 PIPE TERM ; } || { echo "Gtk+Tests:ERROR: Failed to start Xvfb environment for X11 target tests."; exit 1; }
DISPLAY=:$XID
export DISPLAY
fi
./tests/bamfdaemon/ 0000755 0000156 0000165 00000000000 12704153443 014333 5 ustar jenkins jenkins ./tests/bamfdaemon/test-bamf.c 0000644 0000156 0000165 00000005665 12704153435 016376 0 ustar jenkins jenkins /*
* Copyright (C) 2011 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 Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
void test_application_create_suite (GDBusConnection *connection);
void test_matcher_create_suite (GDBusConnection *connection);
void test_view_create_suite (GDBusConnection *connection);
void test_window_create_suite (void);
static int result = 1;
static gboolean
not_fatal_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data)
{
// Don't crash if used
return FALSE;
}
void
ignore_fatal_errors (void)
{
g_test_log_set_fatal_handler (not_fatal_log_handler, NULL);
}
static void
on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer data)
{
GMainLoop *loop = data;
GtkIconTheme *icon_theme;
g_setenv ("BAMF_TEST_MODE", "TRUE", TRUE);
g_setenv ("PATH", TESTDIR"/data/bin", TRUE);
icon_theme = gtk_icon_theme_get_default ();
gtk_icon_theme_prepend_search_path (icon_theme, TESTDIR"/data/icons");
test_matcher_create_suite (connection);
test_view_create_suite (connection);
test_window_create_suite ();
test_application_create_suite (connection);
result = g_test_run ();
g_main_loop_quit (loop);
}
static void
on_name_lost (GDBusConnection *connection, const gchar *name, gpointer data)
{
GMainLoop *loop = data;
g_main_loop_quit (loop);
}
gint
main (gint argc, gchar *argv[])
{
GMainLoop *loop;
GFile *tmp_dir;
gchar *tmp_path;
tmp_path = g_dir_make_tmp (".bamfhomedataXXXXXX", NULL);
tmp_dir = g_file_new_for_path (tmp_path);
g_file_make_directory (tmp_dir, NULL, NULL);
g_setenv ("XDG_DATA_HOME", tmp_path, TRUE);
g_free (tmp_path);
gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
glibtop_init ();
loop = g_main_loop_new (NULL, FALSE);
g_bus_own_name (G_BUS_TYPE_SESSION,
BAMF_DBUS_SERVICE_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus_acquired,
NULL,
on_name_lost,
loop,
NULL);
g_main_loop_run (loop);
g_file_delete (tmp_dir, NULL, NULL);
g_object_unref (tmp_dir);
return result;
}
./tests/bamfdaemon/test-application.c 0000644 0000156 0000165 00000145001 12704153435 017761 0 ustar jenkins jenkins /*
* Copyright (C) 2009-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include
#include
#include
#include
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-window-test.h"
#define DESKTOP_FILE TESTDIR"/data/test-bamf-app.desktop"
void ignore_fatal_errors (void);
static gboolean signal_seen = FALSE;
static gboolean signal_result = FALSE;
static char * signal_window = NULL;
static GDBusConnection * gdbus_connection = NULL;
static GFile *
write_data_to_tmp_file (const gchar *data)
{
GFile *tmp;
GFileIOStream *iostream;
GOutputStream *output;
tmp = g_file_new_tmp (NULL, &iostream, NULL);
if (!tmp)
{
if (iostream)
g_object_unref (iostream);
return NULL;
}
output = g_io_stream_get_output_stream (G_IO_STREAM (iostream));
if (!g_output_stream_write_all (output, data, strlen (data), NULL, NULL, NULL))
{
g_object_unref (tmp);
tmp = NULL;
}
g_object_unref (output);
return tmp;
}
static void
test_allocation (void)
{
BamfApplication *application;
/* Check it allocates */
application = bamf_application_new ();
g_assert (BAMF_IS_APPLICATION (application));
g_object_unref (application);
application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
g_assert (BAMF_IS_APPLICATION (application));
g_object_unref (application);
}
static void
test_type (void)
{
BamfApplication *application = bamf_application_new ();
g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM);
g_object_unref (application);
}
static void
test_type_set (void)
{
BamfApplication *application = bamf_application_new ();
bamf_application_set_application_type (application, BAMF_APPLICATION_WEB);
g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_WEB);
bamf_application_set_application_type (application, BAMF_APPLICATION_SYSTEM);
g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM);
g_object_unref (application);
}
static void
test_type_set_invalid (void)
{
ignore_fatal_errors();
BamfApplication *application = bamf_application_new ();
bamf_application_set_application_type (application, BAMF_APPLICATION_UNKNOWN);
g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM);
bamf_application_set_application_type (application, -1);
g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM);
g_object_unref (application);
}
static void
test_desktop_file (void)
{
BamfApplication *application = bamf_application_new ();
g_assert (bamf_application_get_desktop_file (application) == NULL);
bamf_application_set_desktop_file (application, DESKTOP_FILE);
g_assert (g_strcmp0 (bamf_application_get_desktop_file (application), DESKTOP_FILE) == 0);
g_object_unref (application);
application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
g_assert (g_strcmp0 (bamf_application_get_desktop_file (application), DESKTOP_FILE) == 0);
g_object_unref (application);
}
static void
test_desktop_icon (void)
{
BamfApplication *application;
const char *icon_desktop = TESTDIR"/data/icon.desktop";
application = bamf_application_new_from_desktop_file (icon_desktop);
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (application);
}
static void
test_desktop_icon_empty (void)
{
BamfApplication *application;
const char no_icon_desktop[] = TESTDIR"/data/no-icon.desktop";
application = bamf_application_new_from_desktop_file (no_icon_desktop);
g_assert_cmpstr (bamf_application_get_desktop_file (application), ==, no_icon_desktop);
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, BAMF_APPLICATION_DEFAULT_ICON);
g_object_unref (application);
}
static void
test_desktop_icon_invalid (void)
{
BamfApplication *application;
const char *invalid_icon_desktop = TESTDIR"/data/test-bamf-app.desktop";
application = bamf_application_new_from_desktop_file (invalid_icon_desktop);
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, BAMF_APPLICATION_DEFAULT_ICON);
g_object_unref (application);
}
static void
test_icon_class_name (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (lwin);
g_object_unref (test);
g_object_unref (application);
}
static void
test_icon_exec_string (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "class", "test-bamf-icon");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (lwin);
g_object_unref (test);
g_object_unref (application);
}
static void
test_icon_embedded (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "class", "python execution-script.py");
bamf_legacy_window_test_set_icon (lwin, "test-bamf-icon");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (lwin);
g_object_unref (test);
g_object_unref (application);
}
static void
test_icon_priority (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "test-bamf-pixmap");
bamf_legacy_window_test_set_icon (lwin, "bamf-custom-icon");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
application = bamf_application_new ();
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (application);
application = bamf_application_new ();
bamf_legacy_window_test_set_wmclass (lwin, NULL, NULL);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-pixmap");
g_object_unref (application);
application = bamf_application_new ();
g_free (lwin->exec);
lwin->exec = NULL;
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "bamf-custom-icon");
g_object_unref (application);
g_object_unref (lwin);
g_object_unref (test);
}
static void
test_icon_generic_class (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
lwin = bamf_legacy_window_test_new (20, "window", "python", "execution-script");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
application = bamf_application_new ();
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "python");
g_object_unref (application);
application = bamf_application_new ();
bamf_legacy_window_test_set_icon (lwin, "bamf-custom-icon");
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "bamf-custom-icon");
g_object_unref (application);
g_object_unref (lwin);
g_object_unref (test);
}
static void
test_icon_generic_exec (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
lwin = bamf_legacy_window_test_new (20, "window", "class", "python2.7");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
application = bamf_application_new ();
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "python2.7");
g_object_unref (application);
application = bamf_application_new ();
bamf_legacy_window_test_set_icon (lwin, "bamf-custom-icon");
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "bamf-custom-icon");
g_object_unref (application);
g_object_unref (lwin);
g_object_unref (test);
}
static void
test_icon_full_path (void)
{
BamfApplication *application;
GKeyFile *key_file;
const char* test_app = TESTDIR"/data/test-bamf-app.desktop";
const char* test_icon = TESTDIR"/data/icons/test-bamf-icon.png";
g_assert (g_file_test (test_icon, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
key_file = g_key_file_new ();
g_key_file_load_from_file (key_file, test_app, G_KEY_FILE_NONE, NULL);
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, test_icon);
gchar *key_data = g_key_file_to_data (key_file, NULL, NULL);
GFile *tmp_file = write_data_to_tmp_file (key_data);
gchar *path = g_file_get_path (tmp_file);
application = bamf_application_new_from_desktop_file (path);
g_file_delete (tmp_file, NULL, NULL);
g_object_unref (tmp_file);
g_key_file_free (key_file);
g_free (key_data);
g_free (path);
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, test_icon);
g_object_unref (application);
}
static void
test_icon_full_path_invalid (void)
{
BamfApplication *application;
GKeyFile *key_file;
const char* test_app = TESTDIR"/data/test-bamf-app.desktop";
const char* invalid_test_icon = TESTDIR"/data/icons/not-existent-icon-file.png";
g_assert (!g_file_test (invalid_test_icon, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
key_file = g_key_file_new ();
g_key_file_load_from_file (key_file, test_app, G_KEY_FILE_NONE, NULL);
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, invalid_test_icon);
gchar *key_data = g_key_file_to_data (key_file, NULL, NULL);
GFile *tmp_file = write_data_to_tmp_file (key_data);
gchar *path = g_file_get_path (tmp_file);
application = bamf_application_new_from_desktop_file (path);
g_file_delete (tmp_file, NULL, NULL);
g_object_unref (tmp_file);
g_key_file_free (key_file);
g_free (key_data);
g_free (path);
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, BAMF_APPLICATION_DEFAULT_ICON);
g_object_unref (application);
}
static void
test_get_mime_types (void)
{
BamfApplication *application;
const char* mime_types_desktop = TESTDIR"/data/mime-types.desktop";
application = bamf_application_new_from_desktop_file (mime_types_desktop);
g_assert_cmpstr (bamf_application_get_desktop_file (application), ==, mime_types_desktop);
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert_cmpuint (g_strv_length (mimes), ==, 7);
g_assert_cmpstr (mimes[0], ==, "text/plain");
g_assert_cmpstr (mimes[1], ==, "text/x-chdr");
g_assert_cmpstr (mimes[2], ==, "text/x-csrc");
g_assert_cmpstr (mimes[3], ==, "text/html");
g_assert_cmpstr (mimes[4], ==, "text/css");
g_assert_cmpstr (mimes[5], ==, "text/x-diff");
g_assert_cmpstr (mimes[6], ==, "application/xml");
g_assert_cmpstr (mimes[7], ==, NULL);
g_strfreev (mimes);
g_object_unref (application);
}
static void
test_get_mime_types_none (void)
{
BamfApplication *application;
const char* mime_types_desktop = TESTDIR"/data/test-bamf-app.desktop";
application = bamf_application_new_from_desktop_file (mime_types_desktop);
g_assert_cmpstr (bamf_application_get_desktop_file (application), ==, mime_types_desktop);
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert (!mimes);
g_object_unref (application);
}
static void
on_urgent_changed (BamfApplication *application, gboolean result, gpointer data)
{
signal_seen = TRUE;
signal_result = result;
}
static void
test_urgent (void)
{
signal_seen = FALSE;
BamfApplication *application;
BamfWindow *window1, *window2;
BamfLegacyWindowTest *test1, *test2;
application = bamf_application_new ();
g_signal_connect (G_OBJECT (application), "urgent-changed", (GCallback) on_urgent_changed, NULL);
test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
// Ensure we are not visible with no windows
g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that when added, we signaled properly
g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that we unset and signal properly
g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_attention (test1, TRUE);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Ensure that when adding a skip-tasklist window, we dont set this to visible
g_assert (bamf_view_is_urgent (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
g_assert (bamf_view_is_urgent (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_attention (test1, FALSE);
g_assert (!bamf_view_is_urgent (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (!signal_result);
}
static void
on_active_changed (BamfApplication *application, gboolean result, gpointer data)
{
signal_seen = TRUE;
signal_result = result;
}
static void
test_active (void)
{
signal_seen = FALSE;
BamfApplication *application;
BamfWindow *window1, *window2;
BamfLegacyWindowTest *test1, *test2;
application = bamf_application_new ();
g_signal_connect (G_OBJECT (application), "active-changed", (GCallback) on_active_changed, NULL);
test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
// Ensure we are not active with no windows
g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that when added, we signaled properly
g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that we unset and signal properly
g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_active (test1, TRUE);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Ensure that when adding a skip-tasklist window, we dont set this to visible
g_assert (bamf_view_is_active (BAMF_VIEW (application)));
g_assert (!signal_seen);
while (g_main_context_pending (NULL)) g_main_context_iteration(NULL, TRUE);
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
g_assert (bamf_view_is_active (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_active (test1, FALSE);
g_assert (!signal_seen);
g_assert (bamf_view_is_active (BAMF_VIEW (application)));
while (g_main_context_pending (NULL)) g_main_context_iteration(NULL, TRUE);
g_assert (!bamf_view_is_active (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (!signal_result);
}
static void
test_get_xids (void)
{
BamfApplication *application;
BamfWindow *window1, *window2;
BamfLegacyWindowTest *lwin1, *lwin2;
GVariant *container;
GVariantIter *xids;
gboolean found;
guint32 xid;
application = bamf_application_new ();
lwin1 = bamf_legacy_window_test_new (25, "window1", "class", "exec");
lwin2 = bamf_legacy_window_test_new (50, "window2", "class", "exec");
window1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin1));
window2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin2));
container = bamf_application_get_xids (application);
g_assert (g_variant_type_equal (g_variant_get_type (container),
G_VARIANT_TYPE ("(au)")));
g_assert (g_variant_n_children (container) == 1);
g_variant_get (container, "(au)", &xids);
g_assert (g_variant_iter_n_children (xids) == 0);
g_variant_iter_free (xids);
g_variant_unref (container);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
container = bamf_application_get_xids (application);
g_assert (g_variant_n_children (container) == 1);
g_variant_get (container, "(au)", &xids);
g_assert (g_variant_iter_n_children (xids) == 2);
found = FALSE;
while (g_variant_iter_loop (xids, "u", &xid))
{
if (xid == 25)
{
found = TRUE;
break;
}
}
g_assert (found);
found = FALSE;
g_variant_get (container, "(au)", &xids);
while (g_variant_iter_loop (xids, "u", &xid))
{
if (xid == 50)
{
found = TRUE;
break;
}
}
g_assert (found);
g_variant_iter_free (xids);
g_variant_unref (container);
g_object_unref (lwin1);
g_object_unref (lwin2);
g_object_unref (window1);
g_object_unref (window2);
g_object_unref (application);
}
static void
test_manages_xid (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "class", "exec");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert (bamf_application_manages_xid (application, 20));
g_object_unref (lwin);
g_object_unref (test);
g_object_unref (application);
}
static void
test_get_window (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *test;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "class", "exec");
test = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (test));
g_assert (bamf_application_get_window (application, 20) == test);
g_object_unref (lwin);
g_object_unref (test);
g_object_unref (application);
}
static void
on_user_visible_changed (BamfApplication *application, gboolean result, gpointer data)
{
signal_seen = TRUE;
signal_result = result;
}
static void
test_user_visible (void)
{
signal_seen = FALSE;
BamfApplication *application;
BamfWindow *window1, *window2;
BamfLegacyWindowTest *test1, *test2;
application = bamf_application_new ();
g_signal_connect (G_OBJECT (application), "user-visible-changed", (GCallback) on_user_visible_changed, NULL);
test1 = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
test2 = bamf_legacy_window_test_new (20, "Window Y", "class", "exec");
window1 = bamf_window_new (BAMF_LEGACY_WINDOW (test1));
window2 = bamf_window_new (BAMF_LEGACY_WINDOW (test2));
// Ensure we are not visible with no windows
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (application)));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that when added, we signaled properly
g_assert (bamf_view_is_user_visible (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Test that we unset and signal properly
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (!signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_skip (test1, TRUE);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window1));
// Ensure that when adding a skip-tasklist window, we dont set this to visible
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (application)));
g_assert (!signal_seen);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window2));
g_assert (bamf_view_is_user_visible (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_skip (test2, TRUE);
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (window1)));
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (application)));
g_assert (signal_seen);
g_assert (!signal_result);
}
static void
on_window_added (BamfApplication *application, char *window, gpointer data)
{
signal_seen = TRUE;
signal_window = g_strdup (window);
}
static void
test_window_added (void)
{
signal_seen = FALSE;
BamfApplication *application;
BamfWindow *window;
BamfLegacyWindowTest *test;
const char *path;
application = bamf_application_new ();
g_signal_connect (G_OBJECT (application), "window-added", (GCallback) on_window_added, NULL);
test = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
// Ensure we dont signal things that are not on the bus
g_assert (!signal_seen);
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
path = bamf_view_export_on_bus (BAMF_VIEW (window), gdbus_connection);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
g_assert (signal_seen);
g_assert_cmpstr (signal_window, ==, path);
signal_seen = FALSE;
g_object_unref (window);
g_object_unref (test);
g_object_unref (application);
}
static void
on_window_removed (BamfApplication *application, char *window, gpointer data)
{
signal_seen = TRUE;
signal_window = g_strdup (window);
}
static void
test_window_removed (void)
{
signal_seen = FALSE;
BamfApplication *application;
BamfWindow *window;
BamfLegacyWindowTest *test;
const char *path;
application = bamf_application_new ();
g_signal_connect (G_OBJECT (application), "window-removed", (GCallback) on_window_removed, NULL);
test = bamf_legacy_window_test_new (20, "Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
// Ensure we dont signal things that are not on the bus
g_assert (!signal_seen);
path = bamf_view_export_on_bus (BAMF_VIEW (window), gdbus_connection);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (window));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (window));
g_assert (signal_seen);
g_assert (g_strcmp0 (signal_window, path) == 0);
signal_seen = FALSE;
g_object_unref (window);
g_object_unref (test);
g_object_unref (application);
}
static void
test_desktop_app_main_child (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_assert (!bamf_application_get_main_child (application));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win));
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktop_app_main_child_doesnt_match_emblems (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
lwin = bamf_legacy_window_test_new (20, "window", "python", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "window");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), !=, "python");
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktop_app_main_child_doesnt_update_emblems (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new_from_desktop_file (DESKTOP_FILE);
lwin = bamf_legacy_window_test_new (20, "window", "python", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
bamf_legacy_window_test_set_name (lwin, "New Window Name");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "New Window Name");
bamf_legacy_window_test_set_name (lwin, "even-new-name");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "even-new-name");
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_app_main_child (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_assert (!bamf_application_get_main_child (application));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win));
g_object_unref (lwin);
g_object_unref (win);
g_assert (!bamf_application_get_main_child (application));
g_object_unref (application);
}
static void
test_app_main_child_matches_emblems (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_app_main_child_updates_emblems (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
bamf_legacy_window_test_set_name (lwin, "New Window Name");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "New Window Name");
bamf_legacy_window_test_set_name (lwin, "even-new-name");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "even-new-name");
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_app_main_child_multiple_children (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win1;
GList *wins = NULL;
GList *lwins = NULL;
int i;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win1));
for (i = 0; i < 10; ++i)
{
lwin = bamf_legacy_window_test_new (i, "other-window", "", "execution-binary");
lwins = g_list_prepend (lwins, lwin);
wins = g_list_prepend (wins, bamf_window_new (BAMF_LEGACY_WINDOW (lwin)));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (wins->data));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1));
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
}
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1));
g_object_unref (win1);
g_object_unref (application);
g_list_free_full (wins, g_object_unref);
g_list_free_full (lwins, g_object_unref);
}
static void
test_app_main_child_normal_priority (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *dialog, *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (10, "dialog", "python", "execution-binary");
lwin->window_type = BAMF_WINDOW_DIALOG;
dialog = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (dialog));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (dialog));
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "dialog");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "python");
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win));
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon");
g_object_unref (dialog);
g_object_unref (win);
g_object_unref (application);
}
static void
test_app_main_child_on_window_removal (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win1, *win2, *win3, *win4, *dialog;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (10, "window1", NULL, "execution-binary");
win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win1));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (20, "window2", NULL, "execution-binary");
win2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win2));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (21, "dialog", NULL, "execution-binary");
lwin->window_type = BAMF_WINDOW_DIALOG;
dialog = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (dialog));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (30, "window3", NULL, "execution-binary");
win3 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win3));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (40, "window4", NULL, "execution-binary");
win4 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win4));
g_object_unref (lwin);
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win4));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win1));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win2));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win2));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win3));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win3));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (dialog));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (dialog));
g_assert (!bamf_application_get_main_child (application));
g_object_unref (win1);
g_object_unref (win2);
g_object_unref (win3);
g_object_unref (win4);
g_object_unref (dialog);
g_object_unref (application);
}
static void
test_app_main_child_on_window_replace_on_removal (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win));
bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (!bamf_application_get_main_child (application));
bamf_legacy_window_test_set_name (lwin, "don't crash here!");
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktop_app_create_local_desktop_file (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
bamf_application_set_desktop_file (application, DESKTOP_FILE);
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-class", "execution-binary");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (!bamf_application_create_local_desktop_file (application));
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktopless_app_create_local_desktop_file_invalid_exec (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-class", NULL);
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (!bamf_application_create_local_desktop_file (application));
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
verify_application_desktop_file_content (BamfApplication *application)
{
GKeyFile *key_file;
const gchar *desktop_file, *exec;
gchar *str_value;
GError *error = NULL;
BamfView *main_child;
BamfLegacyWindow *main_window;
desktop_file = bamf_application_get_desktop_file (application);
key_file = g_key_file_new ();
g_key_file_load_from_file (key_file, desktop_file, G_KEY_FILE_NONE, &error);
g_assert (!error);
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_TYPE, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
g_clear_pointer (&str_value, g_free);
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
"Encoding", &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, "UTF-8");
g_clear_pointer (&str_value, g_free);
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_VERSION, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, "1.0");
g_clear_pointer (&str_value, g_free);
if (bamf_view_get_name (BAMF_VIEW (application)))
{
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NAME, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, bamf_view_get_name (BAMF_VIEW (application)));
g_clear_pointer (&str_value, g_free);
}
if (bamf_view_get_icon (BAMF_VIEW (application)))
{
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ICON, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, bamf_view_get_icon (BAMF_VIEW (application)));
g_clear_pointer (&str_value, g_free);
}
main_child = bamf_application_get_main_child (application);
main_window = bamf_window_get_window (BAMF_WINDOW (main_child));
exec = bamf_legacy_window_get_exec_string (main_window);
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_EXEC, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, exec);
g_clear_pointer (&str_value, g_free);
const gchar *working_dir = bamf_legacy_window_get_working_dir (main_window);
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_PATH, &error);
gchar *current_dir = g_get_current_dir ();
if (g_strcmp0 (current_dir, working_dir) == 0)
{
g_assert (error);
g_clear_error (&error);
g_assert_cmpstr (str_value, ==, NULL);
}
else
{
g_assert (!error);
g_assert_cmpstr (str_value, ==, working_dir);
g_clear_pointer (&str_value, g_free);
}
g_clear_pointer (¤t_dir, g_free);
g_assert (!g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, &error));
g_assert (!error);
const gchar *class = bamf_legacy_window_get_class_instance_name (main_window);
class = class ? class : bamf_legacy_window_get_class_name (main_window);
if (class)
{
str_value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS, &error);
g_assert (!error);
g_assert_cmpstr (str_value, ==, class);
g_clear_pointer (&str_value, g_free);
}
const gchar *current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (current_desktop)
{
gchar **list;
gsize len;
list = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN,
&len, &error);
g_assert (!error);
g_assert_cmpuint (len, ==, 1);
g_assert_cmpstr (*list, ==, current_desktop);
}
gchar *generator = g_strdup_printf ("X-%sGenerated", current_desktop ? current_desktop : "BAMF");
g_assert (g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, generator, &error));
g_assert (!error);
g_free (generator);
g_key_file_free (key_file);
}
static void
test_desktopless_app_create_local_desktop_file_using_instance_class_basename (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
const gchar *desktop_path;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "awesome --exec");
bamf_legacy_window_test_set_wmclass (lwin, NULL, "instance-class");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_create_local_desktop_file (application));
desktop_path = bamf_application_get_desktop_file (application);
g_assert (desktop_path);
g_assert (g_str_has_suffix (desktop_path, "instance-class.desktop"));
g_assert (g_file_test (desktop_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
verify_application_desktop_file_content (application);
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktopless_app_create_local_desktop_file_using_name_class_basename (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
const gchar *desktop_path;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", "Application!/?Class", "awesome --exec");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_create_local_desktop_file (application));
desktop_path = bamf_application_get_desktop_file (application);
g_assert (desktop_path);
g_assert (g_str_has_suffix (desktop_path, "application___class.desktop"));
g_assert (g_file_test (desktop_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
verify_application_desktop_file_content (application);
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktopless_app_create_local_desktop_file_using_exec_basename (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
const gchar *desktop_path;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "awesome --exec");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_create_local_desktop_file (application));
desktop_path = bamf_application_get_desktop_file (application);
g_assert (desktop_path);
g_assert (g_str_has_suffix (desktop_path, "awesome.desktop"));
g_assert (g_file_test (desktop_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
verify_application_desktop_file_content (application);
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktopless_app_create_local_desktop_file_using_trimmed_exec_basename (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
const gchar *desktop_path;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "python awesome-script.py");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_create_local_desktop_file (application));
desktop_path = bamf_application_get_desktop_file (application);
g_assert (desktop_path);
g_assert (g_str_has_suffix (desktop_path, "awesome-script.desktop"));
g_assert (g_file_test (desktop_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
verify_application_desktop_file_content (application);
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_desktopless_app_create_local_desktop_file_with_working_dir (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "python ./awesome-script.py");
g_clear_pointer (&lwin->working_dir, g_free);
lwin->working_dir = g_strdup ("/home/user/my/fantastic/path");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_assert (bamf_application_create_local_desktop_file (application));
verify_application_desktop_file_content (application);
g_object_unref (lwin);
g_object_unref (win);
g_object_unref (application);
}
static void
test_contain_similar_to_window (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win, *win1, *win2, *win3;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "binary");
bamf_legacy_window_test_set_wmclass (lwin, "ClassName", "ClassInstance");
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (30, "window1", NULL, "binary1");
bamf_legacy_window_test_set_wmclass (lwin, "ClassName", "ClassInstance");
win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (bamf_application_contains_similar_to_window (application, win1));
lwin = bamf_legacy_window_test_new (40, "window2", NULL, "binary2");
bamf_legacy_window_test_set_wmclass (lwin, "ClassName", "ClassInstance2");
win2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (!bamf_application_contains_similar_to_window (application, win2));
lwin = bamf_legacy_window_test_new (50, "window3", NULL, "binary3");
bamf_legacy_window_test_set_wmclass (lwin, "ClassName3", "ClassInstance");
win3 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (!bamf_application_contains_similar_to_window (application, win3));
g_object_unref (win);
g_object_unref (win1);
g_object_unref (win2);
g_object_unref (win3);
g_object_unref (application);
}
static void
test_contain_similar_to_window_null (void)
{
BamfApplication *application;
BamfLegacyWindowTest *lwin;
BamfWindow *win, *win1, *win2, *win3;
application = bamf_application_new ();
lwin = bamf_legacy_window_test_new (20, "window", NULL, "binary");
bamf_legacy_window_test_set_wmclass (lwin, NULL, NULL);
win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win));
g_object_unref (lwin);
lwin = bamf_legacy_window_test_new (30, "window1", NULL, "binary1");
bamf_legacy_window_test_set_wmclass (lwin, NULL, NULL);
win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (bamf_application_contains_similar_to_window (application, win1));
lwin = bamf_legacy_window_test_new (40, "window2", NULL, "binary2");
bamf_legacy_window_test_set_wmclass (lwin, "ClassName", NULL);
win2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (!bamf_application_contains_similar_to_window (application, win2));
lwin = bamf_legacy_window_test_new (50, "window3", NULL, "binary3");
bamf_legacy_window_test_set_wmclass (lwin, NULL, "ClassInstance");
win3 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin));
g_object_unref (lwin);
g_assert (!bamf_application_contains_similar_to_window (application, win3));
g_object_unref (win);
g_object_unref (win1);
g_object_unref (win2);
g_object_unref (win3);
g_object_unref (application);
}
/* Initialize test suite */
void
test_application_create_suite (GDBusConnection *connection)
{
#define DOMAIN "/Application"
gdbus_connection = connection;
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/ContainsSimilarToWindow", test_contain_similar_to_window);
g_test_add_func (DOMAIN"/ContainsSimilarToWindow/Null", test_contain_similar_to_window_null);
g_test_add_func (DOMAIN"/Type", test_type);
g_test_add_func (DOMAIN"/Type/Set", test_type_set);
g_test_add_func (DOMAIN"/Type/Set/Invalid", test_type_set_invalid);
g_test_add_func (DOMAIN"/DesktopFile", test_desktop_file);
g_test_add_func (DOMAIN"/DesktopFile/Icon", test_desktop_icon);
g_test_add_func (DOMAIN"/DesktopFile/Icon/Empty", test_desktop_icon_empty);
g_test_add_func (DOMAIN"/DesktopFile/Icon/Invalid", test_desktop_icon_invalid);
g_test_add_func (DOMAIN"/DesktopFile/Icon/FullPath", test_icon_full_path);
g_test_add_func (DOMAIN"/DesktopFile/Icon/FullPath/Invalid", test_icon_full_path_invalid);
g_test_add_func (DOMAIN"/DesktopFile/MimeTypes/Valid", test_get_mime_types);
g_test_add_func (DOMAIN"/DesktopFile/MimeTypes/None", test_get_mime_types_none);
g_test_add_func (DOMAIN"/DesktopFile/MainChild", test_desktop_app_main_child);
g_test_add_func (DOMAIN"/DesktopFile/MainChild/NotMatchEmblems", test_desktop_app_main_child_doesnt_match_emblems);
g_test_add_func (DOMAIN"/DesktopFile/MainChild/NotUpdatesEmblems", test_desktop_app_main_child_doesnt_update_emblems);
g_test_add_func (DOMAIN"/DesktopFile/CreateLocalDesktopFile", test_desktop_app_create_local_desktop_file);
g_test_add_func (DOMAIN"/DesktopLess/Icon/ClassName", test_icon_class_name);
g_test_add_func (DOMAIN"/DesktopLess/Icon/Exec", test_icon_exec_string);
g_test_add_func (DOMAIN"/DesktopLess/Icon/Embedded", test_icon_embedded);
g_test_add_func (DOMAIN"/DesktopLess/Icon/Priority", test_icon_priority);
g_test_add_func (DOMAIN"/DesktopLess/Icon/Generic/Class", test_icon_generic_class);
g_test_add_func (DOMAIN"/DesktopLess/Icon/Generic/Exec", test_icon_generic_exec);
g_test_add_func (DOMAIN"/DesktopLess/MainChild", test_app_main_child);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/MatchesEmblems", test_app_main_child_matches_emblems);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/UpdatesEmblems", test_app_main_child_updates_emblems);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/MultipleChildren", test_app_main_child_multiple_children);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/NormalPriority", test_app_main_child_normal_priority);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/Removal", test_app_main_child_on_window_removal);
g_test_add_func (DOMAIN"/DesktopLess/MainChild/ReplaceOnRemoval", test_app_main_child_on_window_replace_on_removal);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/InvalidExec", test_desktopless_app_create_local_desktop_file_invalid_exec);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/UsingClassInstance", test_desktopless_app_create_local_desktop_file_using_instance_class_basename);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/UsingClassName", test_desktopless_app_create_local_desktop_file_using_name_class_basename);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/UsingExec", test_desktopless_app_create_local_desktop_file_using_exec_basename);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/UsingTrimmedExec", test_desktopless_app_create_local_desktop_file_using_trimmed_exec_basename);
g_test_add_func (DOMAIN"/DesktopLess/CreateLocalDesktopFile/WithWorkingDir", test_desktopless_app_create_local_desktop_file_with_working_dir);
g_test_add_func (DOMAIN"/ManagesXid", test_manages_xid);
g_test_add_func (DOMAIN"/GetWindow", test_get_window);
g_test_add_func (DOMAIN"/Xids", test_get_xids);
g_test_add_func (DOMAIN"/Events/Active", test_active);
g_test_add_func (DOMAIN"/Events/Urgent", test_urgent);
g_test_add_func (DOMAIN"/Events/UserVisible", test_user_visible);
g_test_add_func (DOMAIN"/Events/WindowAdded", test_window_added);
g_test_add_func (DOMAIN"/Events/WindowRemoved", test_window_removed);
}
./tests/bamfdaemon/test-window.c 0000644 0000156 0000165 00000022470 12704153435 016771 0 ustar jenkins jenkins /*
* Copyright (C) 2009 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
#include
#include "bamf-window.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-window-test.h"
static void test_allocation (void);
static void test_xid (void);
static void test_hints (void);
static void test_active (void);
static void test_urgent (void);
static void test_user_visible (void);
static void test_maximized (void);
static void test_vmaximized (void);
static void test_hmaximized (void);
static void test_hmaximized (void);
static gboolean signal_seen = FALSE;
static gboolean signal_result = FALSE;
void
test_window_create_suite (void)
{
#define DOMAIN "/Window"
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/Xid", test_xid);
g_test_add_func (DOMAIN"/Hints", test_hints);
g_test_add_func (DOMAIN"/Events/Active", test_active);
g_test_add_func (DOMAIN"/Events/Urgent", test_urgent);
g_test_add_func (DOMAIN"/Events/UserVisible", test_user_visible);
g_test_add_func (DOMAIN"/Events/Maximized", test_maximized);
g_test_add_func (DOMAIN"/Events/VerticallyMaximized", test_vmaximized);
g_test_add_func (DOMAIN"/Events/HorizontallyMaximized", test_hmaximized);
}
void
test_allocation (void)
{
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_assert (BAMF_IS_WINDOW (window));
g_object_unref (window);
g_object_unref (test);
}
void
test_hints (void)
{
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test), "HINT_NAME", "HINT_VALUE");
g_assert_cmpstr (bamf_window_get_string_hint (window, "HINT_NAME"), ==, "HINT_VALUE");
g_assert_cmpstr (bamf_window_get_string_hint (window, "INVALID_HINT_NAME"), ==, NULL);
g_object_unref (window);
g_object_unref (test);
}
void
test_xid (void)
{
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_assert (bamf_window_get_xid (window) == 20);
g_object_unref (window);
g_object_unref (test);
}
void
on_urgent_changed (BamfWindow *window, gboolean result, gpointer pointer)
{
signal_seen = TRUE;
signal_result = result;
}
void
test_urgent (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "urgent-changed", (GCallback) on_urgent_changed, NULL);
g_assert (!bamf_view_is_urgent (BAMF_VIEW (window)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_attention (test, TRUE);
g_assert (bamf_view_is_urgent (BAMF_VIEW (window)));
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_attention (test, FALSE);
g_assert (!bamf_view_is_urgent (BAMF_VIEW (window)));
g_assert (signal_seen);
g_assert (!signal_result);
g_object_unref (window);
g_object_unref (test);
}
void
on_active_changed (BamfWindow *window, gboolean result, gpointer pointer)
{
signal_seen = TRUE;
signal_result = result;
}
void
test_active (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "active-changed", (GCallback) on_active_changed, NULL);
g_assert (!bamf_view_is_active (BAMF_VIEW (window)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_active (test, TRUE);
g_assert (bamf_view_is_active (BAMF_VIEW (window)));
g_assert (!signal_seen);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_active (test, FALSE);
g_assert (!bamf_view_is_active (BAMF_VIEW (window)));
g_assert (!signal_seen);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (signal_seen);
g_assert (!signal_result);
g_object_unref (window);
g_object_unref (test);
}
void
on_user_visible_changed (BamfWindow *window, gboolean result, gpointer pointer)
{
signal_seen = TRUE;
signal_result = result;
}
void
test_user_visible (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "user-visible-changed", (GCallback) on_user_visible_changed, NULL);
g_assert (bamf_view_is_user_visible (BAMF_VIEW (window)));
g_assert (!signal_seen);
bamf_legacy_window_test_set_skip (test, TRUE);
g_assert (!bamf_view_is_user_visible (BAMF_VIEW (window)));
g_assert (signal_seen);
g_assert (!signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_skip (test, FALSE);
g_assert (bamf_view_is_user_visible (BAMF_VIEW (window)));
g_assert (signal_seen);
g_assert (signal_result);
g_object_unref (window);
g_object_unref (test);
}
void
on_maximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
{
signal_seen = TRUE;
signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_MAXIMIZED);
}
void
test_maximized (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_maximized_changed, NULL);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (!signal_seen);
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_MAXIMIZED);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_MAXIMIZED);
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (signal_seen);
g_assert (!signal_result);
g_object_unref (window);
g_object_unref (test);
}
void
on_vmaximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
{
signal_seen = TRUE;
signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_VERTICAL_MAXIMIZED);
}
void
test_vmaximized (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_vmaximized_changed, NULL);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (!signal_seen);
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_VERTICAL_MAXIMIZED);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_VERTICAL_MAXIMIZED);
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (signal_seen);
g_assert (!signal_result);
g_object_unref (window);
g_object_unref (test);
}
void
on_hmaximized_changed (BamfWindow *window, gint old, gint new, gpointer pointer)
{
signal_seen = TRUE;
signal_result = (old == BAMF_WINDOW_FLOATING && new == BAMF_WINDOW_HORIZONTAL_MAXIMIZED);
}
void
test_hmaximized (void)
{
signal_seen = FALSE;
BamfWindow *window;
BamfLegacyWindowTest *test;
test = bamf_legacy_window_test_new (20,"Maximized Window X", "class", "exec");
window = bamf_window_new (BAMF_LEGACY_WINDOW (test));
g_signal_connect (G_OBJECT (window), "maximized-changed", (GCallback) on_hmaximized_changed, NULL);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (!signal_seen);
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_HORIZONTAL_MAXIMIZED);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_HORIZONTAL_MAXIMIZED);
g_assert (signal_seen);
g_assert (signal_result);
signal_seen = FALSE;
bamf_legacy_window_test_set_maximized (test, BAMF_WINDOW_FLOATING);
g_assert (bamf_window_maximized (window) == BAMF_WINDOW_FLOATING);
g_assert (signal_seen);
g_assert (!signal_result);
g_object_unref (window);
g_object_unref (test);
}
./tests/bamfdaemon/Makefile.am 0000644 0000156 0000165 00000003750 12704153443 016374 0 ustar jenkins jenkins TESTDIR=$(shell realpath $(abs_top_srcdir)/tests)
noinst_PROGRAMS = \
test-bamf
bamf_test_extra_sources = \
$(top_srcdir)/src/bamf-daemon.c \
$(top_srcdir)/src/bamf-legacy-window.c \
$(top_srcdir)/src/bamf-legacy-window-test.c \
$(top_srcdir)/src/bamf-legacy-screen.c \
$(top_srcdir)/src/bamf-view.c \
$(top_srcdir)/src/bamf-control.c \
$(top_srcdir)/src/bamf-matcher.c \
$(top_srcdir)/src/bamf-application.c \
$(top_srcdir)/src/bamf-window.c \
$(top_srcdir)/src/bamf-tab.c \
$(top_srcdir)/src/bamf-xutils.c \
$(NULL)
bamf_test_extra_headers = \
$(top_srcdir)/src/main.h \
$(top_srcdir)/src/bamf-daemon.h \
$(top_srcdir)/src/bamf-legacy-window.h \
$(top_srcdir)/src/bamf-legacy-window-test.h \
$(top_srcdir)/src/bamf-legacy-screen.h \
$(top_srcdir)/src/bamf-view.h \
$(top_srcdir)/src/bamf-control.h \
$(top_srcdir)/src/bamf-matcher.h \
$(top_srcdir)/src/bamf-window.h \
$(top_srcdir)/src/bamf-tab.h \
$(top_srcdir)/src/bamf-application.h \
$(top_srcdir)/src/bamf-xutils.h \
$(NULL)
test_bamf_SOURCES = \
$(bamf_test_extra_sources) \
$(bamf_test_extra_headers) \
test-bamf.c \
test-view.c \
test-application.c \
test-window.c \
test-matcher.c
test_bamf_CFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
-DWNCK_I_KNOW_THIS_IS_UNSTABLE \
-DTESTDIR=\""$(TESTDIR)"\" \
$(COVERAGE_CFLAGS) \
$(GCC_FLAGS) \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(GTOP_CFLAGS) \
$(MAINTAINER_CFLAGS) \
$(SN_CFLAGS) \
$(WNCK_CFLAGS) \
$(X_CFLAGS) \
$(NULL)
test_bamf_LDADD = \
$(top_builddir)/lib/libbamf-private/libbamf-private.la \
$(GLIB_LIBS) \
$(GTK_LIBS) \
$(GTOP_LIBS) \
$(SN_LIBS) \
$(WNCK_LIBS) \
$(X_LIBS) \
$(NULL)
if EXPORT_ACTIONS_MENU
test_bamf_LDADD += $(DBUSMENU_LIBS)
test_bamf_CFLAGS += $(DBUSMENU_CFLAGS)
test_bamf_CFLAGS += -DEXPORT_ACTIONS_MENU
endif
test_bamf_LDFLAGS = \
-Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions \
$(COVERAGE_LDFLAGS) \
$(NULL)
TEST_BINARY = test-bamf
include $(top_srcdir)/tests/Makefile.am.gtests
./tests/bamfdaemon/test-view.c 0000644 0000156 0000165 00000066771 12704153435 016450 0 ustar jenkins jenkins /*
* Copyright (C) 2009-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include
#include
#include "bamf-view.h"
static GDBusConnection *gdbus_connection = NULL;
static void
test_allocation (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (BAMF_IS_VIEW (view));
g_object_unref (G_OBJECT (view));
}
#define test_string_property(prop) test_##prop
#define declare_test_string_property(prop) \
static void \
test_string_property (prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
g_assert (!bamf_view_get_##prop (view)); \
\
const gchar *new_##prop = "Some" #prop; \
bamf_view_set_##prop (view, new_##prop); \
g_assert_cmpstr (bamf_view_get_##prop (view), ==, new_##prop); \
\
new_##prop = "Another" #prop; \
bamf_view_set_##prop (view, new_##prop); \
g_assert_cmpstr (bamf_view_get_##prop (view), ==, new_##prop); \
\
g_object_unref (view); \
}
declare_test_string_property (name);
declare_test_string_property (icon);
#define test_string_property_exported(prop) test_##prop##_exported
#define declare_test_string_property_exported(prop) \
static void \
test_string_property_exported (prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
g_assert (!bamf_view_get_##prop (view)); \
\
const gchar *new_##prop = "Some" #prop; \
bamf_view_set_##prop (view, new_##prop); \
bamf_view_export_on_bus (view, gdbus_connection); \
g_assert_cmpstr (bamf_view_get_##prop (view), ==, new_##prop); \
\
new_##prop = "Another" #prop; \
bamf_view_set_##prop (view, new_##prop); \
g_assert_cmpstr (bamf_view_get_##prop (view), ==, new_##prop); \
\
g_object_unref (view); \
}
declare_test_string_property_exported (name);
declare_test_string_property_exported (icon);
#define test_boolean_property(prop) test_##prop
#define declare_test_boolean_property(prop) \
static void \
test_boolean_property (prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
g_assert (!bamf_view_is_##prop (view)); \
\
bamf_view_set_##prop (view, TRUE); \
g_assert (bamf_view_is_##prop (view)); \
\
bamf_view_set_##prop (view, FALSE); \
g_assert (!bamf_view_is_##prop (view)); \
\
g_object_unref (view); \
}
declare_test_boolean_property (active);
declare_test_boolean_property (running);
declare_test_boolean_property (urgent);
declare_test_boolean_property (user_visible);
#define test_boolean_property_exported(prop) test_##prop##_exported
#define declare_test_boolean_property_exported(prop) \
static void \
test_boolean_property_exported(prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
bamf_view_set_active (view, TRUE); \
\
bamf_view_export_on_bus (view, gdbus_connection); \
g_assert (bamf_view_is_active (view)); \
\
bamf_view_set_active (view, FALSE); \
g_assert (!bamf_view_is_active (view)); \
\
g_object_unref (view); \
}
declare_test_boolean_property_exported (active);
declare_test_boolean_property_exported (running);
declare_test_boolean_property_exported (urgent);
declare_test_boolean_property_exported (user_visible);
static void
test_path (void)
{
BamfView *view;
const char *path;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (bamf_view_get_path (view) == NULL);
path = bamf_view_export_on_bus (view, gdbus_connection);
g_assert (path);
g_assert (g_strcmp0 (path, bamf_view_get_path (view)) == 0);
g_object_unref (view);
}
static void
test_path_collision (void)
{
int i, j;
for (i = 0; i < 20; i++)
{
GList *views = NULL;
for (j = 0; j < 2000; j++)
{
BamfView * view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (BAMF_IS_VIEW (view));
views = g_list_prepend (views, view);
bamf_view_export_on_bus (view, gdbus_connection);
}
g_list_free_full (views, g_object_unref);
}
}
static void
test_children (void)
{
BamfView *parent;
BamfView *child1, *child2, *child3;
parent = g_object_new (BAMF_TYPE_VIEW, NULL);
child1 = g_object_new (BAMF_TYPE_VIEW, NULL);
child2 = g_object_new (BAMF_TYPE_VIEW, NULL);
child3 = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (bamf_view_get_children (parent) == NULL);
bamf_view_add_child (parent, child1);
g_assert (g_list_length (bamf_view_get_children (parent)) == 1);
g_assert (g_list_nth_data (bamf_view_get_children (parent), 0) == child1);
bamf_view_add_child (parent, child2);
bamf_view_add_child (parent, child3);
g_assert (g_list_length (bamf_view_get_children (parent)) == 3);
bamf_view_close (child1);
g_object_unref (child1);
g_assert (g_list_length (bamf_view_get_children (parent)) == 2);
bamf_view_close (child2);
g_object_unref (child2);
g_assert (g_list_length (bamf_view_get_children (parent)) == 1);
bamf_view_close (child3);
g_object_unref (child3);
g_assert (g_list_length (bamf_view_get_children (parent)) == 0);
bamf_view_close (parent);
g_object_unref (parent);
}
static void
test_children_paths (void)
{
BamfView *parent;
BamfView *child1, *child2, *child3;
GVariant *container;
GVariantIter *paths;
const char *path;
gboolean found;
parent = g_object_new (BAMF_TYPE_VIEW, NULL);
child1 = g_object_new (BAMF_TYPE_VIEW, NULL);
child2 = g_object_new (BAMF_TYPE_VIEW, NULL);
child3 = g_object_new (BAMF_TYPE_VIEW, NULL);
bamf_view_export_on_bus (parent, gdbus_connection);
bamf_view_export_on_bus (child1, gdbus_connection);
bamf_view_export_on_bus (child2, gdbus_connection);
g_assert (bamf_view_get_children (parent) == NULL);
bamf_view_add_child (parent, child1);
bamf_view_add_child (parent, child2);
bamf_view_add_child (parent, child3);
g_assert (g_list_length (bamf_view_get_children (parent)) == 3);
container = bamf_view_get_children_paths (parent);
g_assert (g_variant_type_equal (g_variant_get_type (container),
G_VARIANT_TYPE ("(as)")));
g_assert (g_variant_n_children (container) == 1);
g_variant_get (container, "(as)", &paths);
g_assert (g_variant_iter_n_children (paths) == 2);
g_variant_iter_free (paths);
g_variant_unref (container);
bamf_view_export_on_bus (child3, gdbus_connection);
container = bamf_view_get_children_paths (parent);
g_variant_get (container, "(as)", &paths);
g_assert (g_variant_iter_n_children (paths) == 3);
found = FALSE;
while (g_variant_iter_loop (paths, "s", &path))
{
if (g_strcmp0 (path, bamf_view_get_path (child1)) == 0)
{
found = TRUE;
break;
}
}
g_assert (found);
found = FALSE;
g_variant_get (container, "(as)", &paths);
while (g_variant_iter_loop (paths, "s", &path))
{
if (g_strcmp0 (path, bamf_view_get_path (child2)) == 0)
{
found = TRUE;
break;
}
}
g_variant_iter_free (paths);
g_assert (found);
found = FALSE;
g_variant_get (container, "(as)", &paths);
while (g_variant_iter_loop (paths, "s", &path))
{
if (g_strcmp0 (path, bamf_view_get_path (child3)) == 0)
{
found = TRUE;
break;
}
}
g_variant_iter_free (paths);
g_assert (found);
g_variant_unref (container);
g_object_unref (child1);
g_object_unref (child2);
g_object_unref (child3);
g_object_unref (parent);
}
static gboolean boolean_event_fired = FALSE;
static gboolean boolean_event_result = FALSE;
static guint boolean_event_calls = 0;
static void
on_boolean_event (BamfView *view, gboolean event, gpointer pointer)
{
boolean_event_fired = TRUE;
boolean_event_result = event;
}
#define test_boolean_property_event(prop) test_##prop##_event
#define declare_test_boolean_property_event(prop) \
static void \
test_boolean_property_event (prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
g_assert (!bamf_view_is_##prop (view)); \
\
g_signal_connect (G_OBJECT (view), #prop "_changed", \
(GCallback) on_boolean_event, NULL); \
\
boolean_event_fired = FALSE; \
boolean_event_result = FALSE; \
\
bamf_view_set_##prop (view, TRUE); \
g_assert (bamf_view_is_##prop (view)); \
\
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); \
g_assert (boolean_event_fired); \
g_assert (boolean_event_result); \
\
boolean_event_fired = FALSE; \
bamf_view_set_##prop (view, FALSE); \
g_assert (!bamf_view_is_##prop (view)); \
\
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); \
g_assert (boolean_event_fired); \
g_assert (!boolean_event_result); \
\
g_object_unref (view); \
}
declare_test_boolean_property_event (active);
declare_test_boolean_property_event (running);
declare_test_boolean_property_event (urgent);
declare_test_boolean_property_event (user_visible);
static gboolean string_event_fired = FALSE;
static char * string_event_result = NULL;
static void
on_string_event (BamfView *view, const gchar *oval, const gchar *nval, gpointer pointer)
{
string_event_fired = TRUE;
g_free (string_event_result);
string_event_result = g_strdup (nval);
}
static void
test_name_event (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (!bamf_view_get_name (view));
g_signal_connect (G_OBJECT (view), "name_changed",
(GCallback) on_string_event, NULL);
string_event_fired = FALSE;
string_event_result = NULL;
bamf_view_set_name (view, "NewName");
g_assert_cmpstr (bamf_view_get_name (view), ==, "NewName");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (string_event_fired);
g_assert_cmpstr (string_event_result, ==, "NewName");
string_event_fired = FALSE;
bamf_view_set_name (view, "AnotherName");
g_assert_cmpstr (bamf_view_get_name (view), ==, "AnotherName");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (string_event_fired);
g_assert_cmpstr (string_event_result, ==, "AnotherName");
g_object_unref (view);
}
static gboolean property_event_fired = FALSE;
static char * property_event_name = NULL;
static void
on_property_changed (BamfView *view, GParamSpec *param, BamfView *self)
{
g_free (property_event_name);
property_event_fired = TRUE;
property_event_name = g_strdup (param->name);
}
static void
test_icon_event (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (!bamf_view_get_icon (view));
g_signal_connect (G_OBJECT (view), "notify::icon",
(GCallback) on_property_changed, NULL);
property_event_fired = FALSE;
property_event_name = NULL;
bamf_view_set_icon (view, "NewIcon");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (property_event_fired);
g_assert_cmpstr (property_event_name, ==, "icon");
property_event_fired = FALSE;
bamf_view_set_icon (view, "AnotherIcon");
g_assert_cmpstr (bamf_view_get_icon (view), ==, "AnotherIcon");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (property_event_fired);
g_assert_cmpstr (property_event_name, ==, "icon");
g_object_unref (view);
}
#define test_boolean_property_event_exported(prop) test_##prop##_event_exported
#define declare_test_boolean_property_event_exported(prop) \
static void \
test_boolean_property_event_exported (prop) (void) \
{ \
BamfView *view; \
\
view = g_object_new (BAMF_TYPE_VIEW, NULL); \
g_assert (!bamf_view_is_##prop (view)); \
\
g_signal_connect (G_OBJECT (view), #prop "_changed", \
(GCallback) on_boolean_event, NULL); \
\
boolean_event_fired = FALSE; \
boolean_event_result = FALSE; \
\
bamf_view_set_##prop (view, TRUE); \
\
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); \
g_assert (boolean_event_fired); \
g_assert (boolean_event_result); \
boolean_event_fired = FALSE; \
boolean_event_result = FALSE; \
\
bamf_view_export_on_bus (view, gdbus_connection); \
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); \
g_assert (boolean_event_fired); \
g_assert (boolean_event_result); \
\
boolean_event_fired = FALSE; \
bamf_view_set_##prop (view, FALSE); \
g_assert (!bamf_view_is_##prop (view)); \
\
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); \
g_assert (boolean_event_fired); \
g_assert (!boolean_event_result); \
\
g_object_unref (view); \
}
declare_test_boolean_property_event_exported (active);
declare_test_boolean_property_event_exported (running);
declare_test_boolean_property_event_exported (urgent);
declare_test_boolean_property_event_exported (user_visible);
static void
test_name_event_exported (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (!bamf_view_get_name (view));
g_signal_connect (G_OBJECT (view), "name_changed",
(GCallback) on_string_event, NULL);
string_event_fired = FALSE;
string_event_result = NULL;
bamf_view_set_name (view, "NewName");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (string_event_fired);
g_assert_cmpstr (string_event_result, ==, "NewName");
string_event_fired = FALSE;
g_free (string_event_result);
string_event_result = NULL;
bamf_view_export_on_bus (view, gdbus_connection);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (string_event_fired);
g_assert_cmpstr (string_event_result, ==, "NewName");
string_event_fired = FALSE;
bamf_view_set_name (view, "AnotherName");
g_assert_cmpstr (bamf_view_get_name (view), ==, "AnotherName");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (string_event_fired);
g_assert_cmpstr (string_event_result, ==, "AnotherName");
g_object_unref (view);
}
static void
test_icon_event_exported (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (!bamf_view_get_icon (view));
g_signal_connect (G_OBJECT (view), "notify::icon",
(GCallback) on_property_changed, NULL);
property_event_fired = FALSE;
property_event_name = NULL;
bamf_view_set_icon (view, "NewIcon");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (property_event_fired);
g_assert_cmpstr (property_event_name, ==, "icon");
property_event_fired = FALSE;
g_free (property_event_name);
property_event_name = NULL;
bamf_view_export_on_bus (view, gdbus_connection);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (property_event_fired);
g_assert_cmpstr (property_event_name, ==, "icon");
property_event_fired = FALSE;
bamf_view_set_icon (view, "AnotherIcon");
g_assert_cmpstr (bamf_view_get_icon (view), ==, "AnotherIcon");
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert (property_event_fired);
g_assert_cmpstr (property_event_name, ==, "icon");
g_object_unref (view);
}
static void
on_boolean_event_count (BamfView *view, gboolean event, gpointer pointer)
{
boolean_event_calls++;
boolean_event_result = event;
}
static void
test_active_event_count (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
g_assert (!bamf_view_is_active (view));
g_signal_connect (G_OBJECT (view), "active-changed",
(GCallback) on_boolean_event_count, NULL);
boolean_event_calls = 0;
bamf_view_set_active (view, TRUE);
g_assert (bamf_view_is_active (view));
g_assert_cmpuint (boolean_event_calls, ==, 0);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert_cmpuint (boolean_event_calls, ==, 1);
g_assert (boolean_event_result);
boolean_event_calls = 0;
bamf_view_set_active (view, FALSE);
bamf_view_set_active (view, TRUE);
bamf_view_set_active (view, FALSE);
while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE);
g_assert_cmpuint (boolean_event_calls, ==, 1);
g_assert (!boolean_event_result);
g_object_unref (view);
}
static gboolean child_added_event_fired;
static char * child_added_event_result;
static void
on_child_added (BamfView *view, char *path, gpointer pointer)
{
child_added_event_fired = TRUE;
child_added_event_result = g_strdup (path);
}
static void
test_child_added_event (void)
{
BamfView *parent;
BamfView *child;
parent = g_object_new (BAMF_TYPE_VIEW, NULL);
child = g_object_new (BAMF_TYPE_VIEW, NULL);
bamf_view_export_on_bus (parent, gdbus_connection);
bamf_view_export_on_bus (child, gdbus_connection);
g_signal_connect (G_OBJECT (parent), "child-added",
(GCallback) on_child_added, NULL);
child_added_event_fired = FALSE;
bamf_view_add_child (parent, child);
g_assert (child_added_event_fired);
g_assert (g_strcmp0 (bamf_view_get_path (child), child_added_event_result) == 0);
bamf_view_close (child);
bamf_view_close (parent);
g_object_unref (child);
g_object_unref (parent);
}
static gboolean child_removed_event_fired;
static char * child_removed_event_result;
static void
on_child_removed (BamfView *view, char *path, gpointer pointer)
{
child_removed_event_fired = TRUE;
child_removed_event_result = g_strdup (path);
}
static void
test_child_removed_event (void)
{
BamfView *parent;
BamfView *child;
parent = g_object_new (BAMF_TYPE_VIEW, NULL);
child = g_object_new (BAMF_TYPE_VIEW, NULL);
bamf_view_export_on_bus (parent, gdbus_connection);
bamf_view_export_on_bus (child, gdbus_connection);
bamf_view_add_child (parent, child);
g_signal_connect (G_OBJECT (parent), "child-removed",
(GCallback) on_child_removed, NULL);
child_removed_event_fired = FALSE;
bamf_view_remove_child (parent, child);
g_assert (child_removed_event_fired);
g_assert (g_strcmp0 (bamf_view_get_path (child), child_removed_event_result) == 0);
g_object_unref (child);
g_object_unref (parent);
}
static gboolean closed_event_fired;
static void
on_closed (BamfView *view, gpointer pointer)
{
closed_event_fired = TRUE;
}
static void
test_closed_event (void)
{
BamfView *view;
view = g_object_new (BAMF_TYPE_VIEW, NULL);
bamf_view_export_on_bus (view, gdbus_connection);
g_signal_connect (G_OBJECT (view), "closed",
(GCallback) on_closed, NULL);
closed_event_fired = FALSE;
bamf_view_close (view);
g_assert (closed_event_fired);
g_object_unref (view);
}
static void
test_parent_child_out_of_order_unref (void)
{
BamfView *parent, *child;
parent = g_object_new (BAMF_TYPE_VIEW, NULL);
child = g_object_new (BAMF_TYPE_VIEW, NULL);
bamf_view_export_on_bus (parent, gdbus_connection);
bamf_view_export_on_bus (child, gdbus_connection);
bamf_view_add_child (parent, child);
g_object_unref (parent);
g_object_unref (child);
}
/* Test Suite */
void
test_view_create_suite (GDBusConnection *connection)
{
#define DOMAIN "/View"
gdbus_connection = connection;
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/Name", test_string_property (name));
g_test_add_func (DOMAIN"/Name/Exported", test_string_property_exported (name));
g_test_add_func (DOMAIN"/Icon", test_string_property (icon));
g_test_add_func (DOMAIN"/Icon/Exported", test_string_property_exported (icon));
g_test_add_func (DOMAIN"/Active", test_boolean_property (active));
g_test_add_func (DOMAIN"/Active/Exported", test_boolean_property_exported (active));
g_test_add_func (DOMAIN"/Running", test_boolean_property (running));
g_test_add_func (DOMAIN"/Running/Exported", test_boolean_property_exported (running));
g_test_add_func (DOMAIN"/Urgent", test_boolean_property (urgent));
g_test_add_func (DOMAIN"/Urgent/Exported", test_boolean_property_exported (urgent));
g_test_add_func (DOMAIN"/UserVisible", test_boolean_property (user_visible));
g_test_add_func (DOMAIN"/UserVisible/Exported", test_boolean_property_exported (user_visible));
g_test_add_func (DOMAIN"/Path", test_path);
g_test_add_func (DOMAIN"/Path/Collision", test_path_collision);
g_test_add_func (DOMAIN"/Events/Close", test_closed_event);
g_test_add_func (DOMAIN"/Events/Active", test_boolean_property_event (active));
g_test_add_func (DOMAIN"/Events/Name", test_name_event);
g_test_add_func (DOMAIN"/Events/Name/Exported", test_name_event_exported);
g_test_add_func (DOMAIN"/Events/Icon", test_icon_event);
g_test_add_func (DOMAIN"/Events/Icon/Exported", test_icon_event_exported);
g_test_add_func (DOMAIN"/Events/Active/Count", test_active_event_count);
g_test_add_func (DOMAIN"/Events/Active/Exported", test_boolean_property_event_exported (active));
g_test_add_func (DOMAIN"/Events/Running", test_boolean_property_event (running));
g_test_add_func (DOMAIN"/Events/Running/Exported", test_boolean_property_event_exported (running));
g_test_add_func (DOMAIN"/Events/Urgent", test_boolean_property_event (urgent));
g_test_add_func (DOMAIN"/Events/Urgent/Exported", test_boolean_property_event_exported (urgent));
g_test_add_func (DOMAIN"/Events/UserVisible", test_boolean_property_event (user_visible));
g_test_add_func (DOMAIN"/Events/UserVisible/Exported", test_boolean_property_event_exported (user_visible));
g_test_add_func (DOMAIN"/Events/ChildAdded", test_child_added_event);
g_test_add_func (DOMAIN"/Events/ChildRemoved", test_child_removed_event);
g_test_add_func (DOMAIN"/Children", test_children);
g_test_add_func (DOMAIN"/Children/Paths", test_children_paths);
g_test_add_func (DOMAIN"/Children/UnrefOrder", test_parent_child_out_of_order_unref);
}
./tests/bamfdaemon/test-matcher.c 0000644 0000156 0000165 00000142626 12704153435 017113 0 ustar jenkins jenkins /*
* Copyright (C) 2009-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
* Marco Trevisan (Treviño)
*
*/
#include
#include
#include "bamf-matcher.h"
#include "bamf-matcher-private.h"
#include "bamf-legacy-screen-private.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-window-test.h"
static GDBusConnection *gdbus_connection = NULL;
#define DOMAIN "/Matcher"
#define DATA_DIR TESTDIR "/data"
#define TEST_BAMF_APP_DESKTOP DATA_DIR "/test-bamf-app.desktop"
static void
export_matcher_on_bus (BamfMatcher *matcher)
{
GError *error = NULL;
g_return_if_fail (BAMF_IS_MATCHER (matcher));
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (matcher),
gdbus_connection, BAMF_DBUS_MATCHER_PATH,
&error);
g_assert (!error);
g_clear_error (&error);
}
static void
cleanup_matcher_tables (BamfMatcher *matcher)
{
g_return_if_fail (BAMF_IS_MATCHER (matcher));
g_hash_table_destroy (matcher->priv->desktop_file_table);
g_hash_table_destroy (matcher->priv->desktop_id_table);
g_hash_table_destroy (matcher->priv->desktop_class_table);
g_list_free (matcher->priv->no_display_desktop);
matcher->priv->desktop_file_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
NULL);
matcher->priv->desktop_id_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
NULL);
matcher->priv->desktop_class_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
matcher->priv->no_display_desktop = NULL;
}
static BamfWindow *
find_window_in_matcher (BamfMatcher *matcher, BamfLegacyWindow *legacy)
{
GList *l;
BamfWindow *found_window = NULL;
for (l = matcher->priv->views; l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
if (bamf_window_get_window (BAMF_WINDOW (l->data)) == legacy)
{
g_assert (!found_window);
found_window = l->data;
}
}
return found_window;
}
static BamfWindow *
find_window_in_app (BamfApplication *app, BamfLegacyWindow *legacy)
{
GList *l;
BamfWindow *found_window = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (app), NULL);
for (l = bamf_view_get_children (BAMF_VIEW (app)); l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
if (bamf_window_get_window (BAMF_WINDOW (l->data)) == legacy)
{
g_assert (!found_window);
found_window = l->data;
}
}
return found_window;
}
static void
test_allocation (void)
{
BamfMatcher *matcher;
/* Check it allocates */
matcher = bamf_matcher_get_default ();
g_assert (BAMF_IS_MATCHER (matcher));
g_object_unref (matcher);
}
static void
test_load_desktop_file (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
GList *l = g_hash_table_lookup (priv->desktop_file_table, "test-bamf-app");
g_assert (l);
g_assert_cmpstr (l->data, ==, TEST_BAMF_APP_DESKTOP);
l = g_hash_table_lookup (priv->desktop_id_table, "test-bamf-app");
g_assert (l);
g_assert_cmpstr (l->data, ==, TEST_BAMF_APP_DESKTOP);
const char *desktop = g_hash_table_lookup (priv->desktop_class_table, TEST_BAMF_APP_DESKTOP);
g_assert_cmpstr (desktop, ==, "test_bamf_app");
g_object_unref (matcher);
}
static void
test_load_desktop_file_autostart (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
gchar *file = g_build_filename (g_get_user_config_dir(), "autostart", "foo-app.desktop", NULL);
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, file);
g_assert (!g_hash_table_lookup (priv->desktop_id_table, "foo-app"));
g_free (file);
g_object_unref (matcher);
}
static void
test_load_desktop_file_no_display_has_lower_prio_same_id (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/no-display/test-bamf-app.desktop");
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
GList *l = g_hash_table_lookup (priv->desktop_file_table, "test-bamf-app");
g_assert (l);
g_assert_cmpstr (l->data, ==, TEST_BAMF_APP_DESKTOP);
g_assert (l->next);
g_assert_cmpstr (l->next->data, ==, DATA_DIR"/no-display/test-bamf-app.desktop");
l = g_hash_table_lookup (priv->desktop_id_table, "test-bamf-app");
g_assert (l);
g_assert_cmpstr (l->data, ==, TEST_BAMF_APP_DESKTOP);
g_assert (l->next);
g_assert_cmpstr (l->next->data, ==, DATA_DIR"/no-display/test-bamf-app.desktop");
g_object_unref (matcher);
}
static void
test_load_desktop_file_no_display_has_lower_prio_different_id (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/test-bamf-app-no-display.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/test-bamf-app-display.desktop");
GList *l = g_hash_table_lookup (priv->desktop_file_table, "test-bamf-app");
g_assert (l);
g_assert_cmpstr (l->data, ==, DATA_DIR"/test-bamf-app-display.desktop");
g_assert (l->next);
g_assert_cmpstr (l->next->data, ==, DATA_DIR"/test-bamf-app-no-display.desktop");
g_object_unref (matcher);
}
static void
test_register_desktop_for_pid (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
guint pid = g_random_int ();
bamf_matcher_register_desktop_file_for_pid (matcher, TEST_BAMF_APP_DESKTOP, pid);
char *desktop = g_hash_table_lookup (priv->registered_pids, GUINT_TO_POINTER (pid));
g_assert_cmpstr (desktop, ==, TEST_BAMF_APP_DESKTOP);
g_object_unref (matcher);
}
static void
test_register_desktop_for_pid_big_number (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
bamf_matcher_register_desktop_file_for_pid (matcher, TEST_BAMF_APP_DESKTOP, G_MAXINT64);
char *desktop = g_hash_table_lookup (priv->registered_pids, GUINT_TO_POINTER (G_MAXINT64));
g_assert_cmpstr (desktop, ==, TEST_BAMF_APP_DESKTOP);
g_object_unref (matcher);
}
static void
test_register_desktop_for_pid_autostart (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
guint pid = g_random_int ();
gchar *desktop = g_build_filename (g_get_user_config_dir(), "autostart", "foo-app.desktop", NULL);
bamf_matcher_register_desktop_file_for_pid (matcher, desktop, pid);
g_free (desktop);
desktop = g_hash_table_lookup (priv->registered_pids, GUINT_TO_POINTER (pid));
g_assert_cmpstr (desktop, ==, NULL);
g_object_unref (matcher);
}
static void
test_register_desktop_for_pid_display (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
guint pid = g_random_int ();
const gchar *desktop = DATA_DIR"/test-bamf-app-display.desktop";
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, desktop);
bamf_matcher_register_desktop_file_for_pid (matcher, desktop, pid);
desktop = g_hash_table_lookup (priv->registered_pids, GUINT_TO_POINTER (pid));
g_assert_cmpstr (desktop, ==, DATA_DIR"/test-bamf-app-display.desktop");
g_object_unref (matcher);
}
static void
test_register_desktop_for_pid_nodisplay (void)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
BamfMatcherPrivate *priv = matcher->priv;
guint pid = g_random_int ();
const gchar *desktop = DATA_DIR"/test-bamf-app-no-display.desktop";
cleanup_matcher_tables (matcher);
bamf_matcher_load_desktop_file (matcher, desktop);
bamf_matcher_register_desktop_file_for_pid (matcher, desktop, pid);
desktop = g_hash_table_lookup (priv->registered_pids, GUINT_TO_POINTER (pid));
g_assert_cmpstr (desktop, ==, NULL);
g_object_unref (matcher);
}
static void
test_open_windows (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindow *window;
BamfLegacyWindowTest *test_win;
guint xid;
const int window_count = 500;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
for (xid = G_MAXUINT; xid > G_MAXUINT-window_count; xid--)
{
gchar *name = g_strdup_printf ("Test Window %u", xid);
gchar *class = g_strdup_printf ("test-class-%u", xid);
gchar *exec = g_strdup_printf ("test-class-%u", xid);
test_win = bamf_legacy_window_test_new (xid, name, class, exec);
window = BAMF_LEGACY_WINDOW (test_win);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_assert (g_list_find (bamf_legacy_screen_get_windows (screen), test_win));
g_assert (find_window_in_matcher (matcher, window));
g_assert (bamf_matcher_get_application_by_xid (matcher, xid));
_bamf_legacy_screen_close_test_window (screen, test_win);
g_assert (!g_list_find (bamf_legacy_screen_get_windows (screen), test_win));
g_assert (!find_window_in_matcher (matcher, window));
g_assert (!bamf_matcher_get_application_by_xid (matcher, xid));
g_free (name);
g_free (class);
g_free (exec);
}
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_desktopless_application (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindow *window;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
GList *test_windows = NULL, *l, *app_children;
guint xid;
const int window_count = 5;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
const char *exec = "test-bamf-app";
const char *class = "test-bamf-app";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
for (xid = G_MAXUINT; xid > G_MAXUINT-window_count; xid--)
{
gchar *name = g_strdup_printf ("Test Window %u", xid);
test_win = bamf_legacy_window_test_new (xid, name, class, exec);
window = BAMF_LEGACY_WINDOW (test_win);
test_windows = g_list_prepend (test_windows, window);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (name);
}
app = bamf_matcher_get_application_by_xid (matcher, G_MAXUINT);
g_assert (app);
app_children = bamf_view_get_children (BAMF_VIEW (app));
g_assert_cmpuint (g_list_length (app_children), ==, window_count);
for (l = test_windows; l; l = l->next)
{
g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (l->data)));
}
g_list_free (test_windows);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_desktop_application (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindow *window;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
GList *test_windows = NULL, *l, *app_children;
guint xid;
const int window_count = 5;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
const char *exec = "testbamfapp";
const char *class = "test_bamf_app";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
for (xid = G_MAXUINT; xid > G_MAXUINT-window_count; xid--)
{
gchar *name = g_strdup_printf ("Test Window %u", xid);
test_win = bamf_legacy_window_test_new (xid, name, class, exec);
window = BAMF_LEGACY_WINDOW (test_win);
test_windows = g_list_prepend (test_windows, window);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (name);
}
app = bamf_matcher_get_application_by_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
g_assert (app);
g_assert (bamf_matcher_get_application_by_xid (matcher, G_MAXUINT) == app);
app_children = bamf_view_get_children (BAMF_VIEW (app));
g_assert_cmpuint (g_list_length (app_children), ==, window_count);
for (l = test_windows; l; l = l->next)
{
g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (l->data)));
}
g_list_free (test_windows);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_new_desktop_matches_unmatched_windows (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
GList *app_children;
guint xid = 0;
const int window_count = 5;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
const char *exec = "testbamfapp";
const char *class = "test_bamf_app";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, TEST_BAMF_APP_DESKTOP));
for (xid = G_MAXUINT; xid > G_MAXUINT-window_count; xid--)
{
gchar *name = g_strdup_printf ("Test Window %u", xid);
test_win = bamf_legacy_window_test_new (xid, name, class, exec);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (name);
}
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
app = bamf_matcher_get_application_by_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
g_assert (app);
app_children = bamf_view_get_children (BAMF_VIEW (app));
g_assert_cmpuint (g_list_length (app_children), ==, window_count);
for (xid = G_MAXUINT; xid > G_MAXUINT-window_count; xid--)
{
g_assert (bamf_matcher_get_application_by_xid (matcher, xid) == app);
}
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_libreoffice_windows (void)
{
BamfMatcher *matcher;
BamfWindow *window;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
guint xid = g_random_int ();
const char *exec = "soffice.bin";
const char *class_instance = "VCLSalFrame.DocumentWindow";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-startcenter.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-base.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-calc.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-draw.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-impress.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-math.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/libreoffice-writer.desktop");
test_win = bamf_legacy_window_test_new (xid, "LibreOffice", "libreoffice-startcenter", exec);
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-startcenter", class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-startcenter.desktop");
g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (test_win)));
bamf_legacy_window_test_set_name (test_win, "FooDoc.odb - LibreOffice Base");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-base", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-startcenter.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-base.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
bamf_legacy_window_test_set_name (test_win, "FooDoc.ods - LibreOffice Calc");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-calc", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-base.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-calc.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
bamf_legacy_window_test_set_name (test_win, "FooDoc.odg - LibreOffice Draw");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-draw", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-calc.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-draw.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
bamf_legacy_window_test_set_name (test_win, "FooDoc.odp - LibreOffice Impress");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-impress", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-draw.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-impress.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
bamf_legacy_window_test_set_name (test_win, "FooDoc.odf - LibreOffice Math");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-math", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-impress.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-math.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
bamf_legacy_window_test_set_name (test_win, "FooDoc.odt - LibreOffice Writer");
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-writer", class_instance);
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-math.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-writer.desktop");
g_assert (app);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 1);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
g_assert (bamf_window_get_window (window) == BAMF_LEGACY_WINDOW (test_win));
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "BarDoc.odt - LibreOffice Writer", "libreoffice-writer", exec);
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-writer", class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_assert_cmpuint (g_list_length (bamf_view_get_children (BAMF_VIEW (app))), ==, 2);
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "BarDoc.ods - LibreOffice Calc", "libreoffice-calc", exec);
bamf_legacy_window_test_set_wmclass (test_win, "libreoffice-calc", class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_assert (bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/libreoffice-calc.desktop"));
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_unity_control_center_panels (void)
{
BamfMatcher *matcher;
BamfWindow *window;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
char *hint;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
guint xid = g_random_int ();
const char *exec = "unity-control-center";
const char *class_name = "Unity-control-center";
const char *class_instance = "unity-control-center";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/unity-control-center.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/unity-display-panel.desktop");
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/unity-mouse-panel.desktop");
test_win = bamf_legacy_window_test_new (xid, "System Settings", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
bamf_legacy_window_test_set_role (test_win, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _BAMF_DESKTOP_FILE);
g_assert_cmpstr (hint, ==, DATA_DIR"/unity-control-center.desktop");
g_free (hint);
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-control-center.desktop");
g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (test_win)));
bamf_legacy_window_test_set_name (test_win, "Displays");
bamf_legacy_window_test_set_role (test_win, "display");
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-control-center.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-display-panel.desktop");
g_assert (app);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _BAMF_DESKTOP_FILE);
g_assert_cmpstr (hint, ==, DATA_DIR"/unity-display-panel.desktop");
g_free (hint);
bamf_legacy_window_test_set_name (test_win, "Mouse and Touchpad");
bamf_legacy_window_test_set_role (test_win, "mouse");
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-display-panel.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-mouse-panel.desktop");
g_assert (app);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _BAMF_DESKTOP_FILE);
g_assert_cmpstr (hint, ==, DATA_DIR"/unity-mouse-panel.desktop");
g_free (hint);
bamf_legacy_window_test_set_name (test_win, "Invalid Panel");
bamf_legacy_window_test_set_role (test_win, "invalid-role");
g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-mouse-panel.desktop"));
app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/unity-control-center.desktop");
g_assert (app);
window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _BAMF_DESKTOP_FILE);
g_assert_cmpstr (hint, ==, DATA_DIR"/unity-control-center.desktop");
g_free (hint);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_javaws_windows (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app1, *app2, *app3;
GList *app_children;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
"-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
"-Xms8m -Djava.security.manager " \
"-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
"-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
"-Dicedtea-web.bin.name=javaws " \
"-Dicedtea-web.bin.location=/usr/bin/javaws "\
"net.sourceforge.jnlp.runtime.Boot";
const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
const char *class_instance = "sun-awt-X11-XFramePeer";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
guint xid = g_random_int ();
char *exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (exec);
app1 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app1));
app_children = bamf_view_get_children (BAMF_VIEW (app1));
g_assert_cmpuint (g_list_length (app_children), ==, 1);
g_assert (find_window_in_app (app1, BAMF_LEGACY_WINDOW (test_win)));
xid = g_random_int ();
exec = g_strconcat (exec_prefix, " Draw.jnlp", NULL);
test_win = bamf_legacy_window_test_new (xid, "Draw", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (exec);
app2 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app2));
g_assert (app1 != app2);
app_children = bamf_view_get_children (BAMF_VIEW (app2));
g_assert_cmpuint (g_list_length (app_children), ==, 1);
g_assert (find_window_in_app (app2, BAMF_LEGACY_WINDOW (test_win)));
xid = g_random_int ();
exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
test_win = bamf_legacy_window_test_new (xid, "Notepad Subwin", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (exec);
app3 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (app3 == app1);
g_assert (BAMF_IS_APPLICATION (app3));
app_children = bamf_view_get_children (BAMF_VIEW (app3));
g_assert_cmpuint (g_list_length (app_children), ==, 2);
g_assert (find_window_in_app (app3, BAMF_LEGACY_WINDOW (test_win)));
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_javaws_windows_hint_ignored (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
"-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
"-Xms8m -Djava.security.manager " \
"-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
"-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
"-Dicedtea-web.bin.name=javaws " \
"-Dicedtea-web.bin.location=/usr/bin/javaws "\
"net.sourceforge.jnlp.runtime.Boot ";
const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
const char *class_instance = "sun-awt-X11-XFramePeer";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
guint xid = g_random_int ();
guint pid = g_random_int ();
char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
test_win->pid = pid;
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (exec);
bamf_matcher_register_desktop_file_for_pid (matcher, DATA_DIR"/icedtea-netx-javaws.desktop", pid);
char *hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _BAMF_DESKTOP_FILE);
g_assert (hint == NULL);
app = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app));
g_assert (bamf_application_get_desktop_file (app) == NULL);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_javaws_windows_no_desktop_match (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws " \
"-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
"-Xms8m -Djava.security.manager " \
"-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
"-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
"-Dicedtea-web.bin.name=javaws " \
"-Dicedtea-web.bin.location=/usr/bin/javaws "\
"net.sourceforge.jnlp.runtime.Boot ";
const char *class_name = "net-sourceforge-jnlp-runtime-Boot";
const char *class_instance = "sun-awt-X11-XFramePeer";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/icedtea-netx-javaws.desktop");
guint xid = g_random_int ();
char *exec = g_strconcat (exec_prefix, "Notepad.jnlp", NULL);
test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
_bamf_legacy_screen_open_test_window (screen, test_win);
g_free (exec);
app = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app));
g_assert (bamf_application_get_desktop_file (app) == NULL);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_qml_app_no_desktop (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app1, *app2, *app3;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
guint xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlApp1", NULL, "qmlscene qmlapp1.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app1 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app1));
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlApp2", NULL, "qmlscene qmlapp2.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app2 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app2));
g_assert (app1 != app2);
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlApp2", NULL, "qmlscene qmlapp2.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app3 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app3));
g_assert (app2 == app3);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_qml_app_desktop (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app1, *app2, *app3;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, DATA_DIR"/bamf-qml-app.desktop");
guint xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin1", NULL, "/path/qmlscene bamf_qml_app.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app1 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app1));
g_assert_cmpstr (bamf_application_get_desktop_file (app1), ==, DATA_DIR"/bamf-qml-app.desktop");
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin1", NULL, "qmlscene files/foo/bamf_qml_app.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app2 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app2));
g_assert (app1 == app2);
xid = g_random_int ();
test_win = bamf_legacy_window_test_new (xid, "QmlApp2", NULL, "qmlscene qmlapp2.qml");
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app3 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (BAMF_IS_APPLICATION (app3));
g_assert (app2 != app3);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_desktop_file_hint_exec (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app1, *app2, *app3;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
guint xid = g_random_int ();
const gchar *exec = "/path/qmlscene --desktop_file_hint "TEST_BAMF_APP_DESKTOP" test-qml-app1.qml";
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin1", NULL, exec);
_bamf_legacy_screen_open_test_window (screen, test_win);
app1 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app1), ==, TEST_BAMF_APP_DESKTOP);
_bamf_legacy_screen_close_test_window (screen, test_win);
xid = g_random_int ();
exec = "/path/qmlscene test-qml-app2.qml --desktop_file_hint "TEST_BAMF_APP_DESKTOP;
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin2", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app2 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app2), ==, TEST_BAMF_APP_DESKTOP);
_bamf_legacy_screen_close_test_window (screen, test_win);
xid = g_random_int ();
exec = "test-bamf-app --desktop_file_hint "TEST_BAMF_APP_DESKTOP;
test_win = bamf_legacy_window_test_new (xid, "AnyAppWin1", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app3 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app3), ==, TEST_BAMF_APP_DESKTOP);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_desktop_file_hint_exec_invalid (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *test_win;
BamfApplication *app1, *app2, *app3;
screen = bamf_legacy_screen_get_default ();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
bamf_matcher_load_desktop_file (matcher, TEST_BAMF_APP_DESKTOP);
guint xid = g_random_int ();
const gchar *exec = "/path/qmlscene --desktop_file_hint invalid-file.desktop test-qml-app1.qml";
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin1", NULL, exec);
_bamf_legacy_screen_open_test_window (screen, test_win);
app1 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app1), ==, NULL);
xid = g_random_int ();
exec = "/path/qmlscene test-qml-app2.qml --desktop_file_hint "TEST_BAMF_APP_DESKTOP"s";
test_win = bamf_legacy_window_test_new (xid, "QmlAppWin2", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app2 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app2), ==, NULL);
g_assert (app2 != app1);
_bamf_legacy_screen_close_test_window (screen, test_win);
xid = g_random_int ();
exec = "test-bamf-app --desktop_file_hint invalid-file";
test_win = bamf_legacy_window_test_new (xid, "AnyAppWin1", NULL, exec);
bamf_legacy_window_test_set_wmclass (test_win, NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, test_win);
app3 = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert_cmpstr (bamf_application_get_desktop_file (app3), ==, TEST_BAMF_APP_DESKTOP);
g_assert (app3 != app1);
g_assert (app3 != app2);
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_match_transient_windows (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *main_window;
BamfLegacyWindowTest *child_window;
BamfApplication *main_app, *child_app;
GList *app_children;
guint32 xid;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
const char *exec = "test-bamf-app";
const char *class = "test-bamf-app";
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
xid = g_random_int ();
main_window = bamf_legacy_window_test_new (xid, "Main Window", class, exec);
_bamf_legacy_screen_open_test_window (screen, main_window);
main_app = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (main_app);
app_children = bamf_view_get_children (BAMF_VIEW (main_app));
g_assert_cmpuint (g_list_length (app_children), ==, 1);
g_assert (find_window_in_app (main_app, BAMF_LEGACY_WINDOW (main_window)));
xid = g_random_int ();
child_window = bamf_legacy_window_test_new (xid, "Child Window", NULL, NULL);
child_window->window_type = BAMF_WINDOW_DIALOG;
child_window->transient_window = BAMF_LEGACY_WINDOW (main_window);
_bamf_legacy_screen_open_test_window (screen, child_window);
child_app = bamf_matcher_get_application_by_xid (matcher, xid);
g_assert (child_app == main_app);
app_children = bamf_view_get_children (BAMF_VIEW (main_app));
g_assert_cmpuint (g_list_length (app_children), ==, 2);
g_assert (find_window_in_app (main_app, BAMF_LEGACY_WINDOW (child_window)));
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_trim_exec_string (void)
{
BamfMatcher *matcher;
char *trimmed;
matcher = bamf_matcher_get_default ();
// Bad prefixes
trimmed = bamf_matcher_get_trimmed_exec (matcher, "gksudo bad-prefix-bin");
g_assert_cmpstr (trimmed, ==, "bad-prefix-bin");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "gksu python very-bad-prefix-script.py");
g_assert_cmpstr (trimmed, ==, "very-bad-prefix-script");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "sudo --opt val=X /usr/bin/bad-prefix-bin");
g_assert_cmpstr (trimmed, ==, "bad-prefix-bin");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "python2.7 /home/foo/bad-prefix-script.py");
g_assert_cmpstr (trimmed, ==, "bad-prefix-script");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python3 /usr/bin/gnome-language-selector");
g_assert_cmpstr (trimmed, ==, "gnome-language-selector");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python3.1");
g_assert_cmpstr (trimmed, ==, "python3.1");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python %u --option val=/path");
g_assert_cmpstr (trimmed, ==, "python");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/mono /usr/share/bar/Foo.exe");
g_assert_cmpstr (trimmed, ==, "foo.exe");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/mono %u --option val=/path");
g_assert_cmpstr (trimmed, ==, "mono");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/cli /usr/share/foo/Bar.exe");
g_assert_cmpstr (trimmed, ==, "bar.exe");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/cli %u --option val=/path");
g_assert_cmpstr (trimmed, ==, "cli");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "sh -c \"binary --option --value %U || exec binary\"");
g_assert_cmpstr (trimmed, ==, "binary");
g_free (trimmed);
// Good prefixes
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/libreoffice --writer %U");
g_assert_cmpstr (trimmed, ==, "libreoffice --writer");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/unity-control-center");
g_assert_cmpstr (trimmed, ==, "unity-control-center");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "unity-control-center foo-panel");
g_assert_cmpstr (trimmed, ==, "unity-control-center foo-panel");
g_free (trimmed);
// Other exec strings
trimmed = bamf_matcher_get_trimmed_exec (matcher, "env FOOVAR=\"bar\" myprog");
g_assert_cmpstr (trimmed, ==, "myprog");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/opt/path/bin/myprog --option %U --foo=daa");
g_assert_cmpstr (trimmed, ==, "myprog");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/qmlscene my-app.qml");
g_assert_cmpstr (trimmed, ==, "my-app");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene /home/user/new-app.qml");
g_assert_cmpstr (trimmed, ==, "new-app");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene $var /home/user/var-new-app.qml");
g_assert_cmpstr (trimmed, ==, "var-new-app");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene --option -foo /home/user/opt-app.qml");
g_assert_cmpstr (trimmed, ==, "opt-app");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene --desktop_file_hint deskapp.desktop desktop-app1.qml");
g_assert_cmpstr (trimmed, ==, "desktop-app1");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene desktop-app2.qml --desktop_file_hint deskapp.desktop");
g_assert_cmpstr (trimmed, ==, "desktop-app2");
g_free (trimmed);
trimmed = bamf_matcher_get_trimmed_exec (matcher, "qmlscene desktop-app3.qml --desktop_file_hint");
g_assert_cmpstr (trimmed, ==, "desktop-app3");
g_free (trimmed);
const char *exec = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
"-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
"-Xms8m -Djava.security.manager " \
"-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
"-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
"-Dicedtea-web.bin.name=javaws " \
"-Dicedtea-web.bin.location=/usr/bin/javaws "\
"net.sourceforge.jnlp.runtime.Boot Notepad.jnlp";
trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
g_free (trimmed);
exec = "/usr/lib/jvm/java-7-oracle/jre/bin/java " \
"-classpath /usr/lib/jvm/java-7-oracle/jre/lib/deploy.jar " \
"-Djava.security.policy=file:/usr/lib/jvm/java-7-oracle/jre/lib/security/javaws.policy " \
"-DtrustProxy=true -Xverify:remote " \
"-Djnlpx.home=/usr/lib/jvm/java-7-oracle/jre/bin " \
"-Djnlpx.remove=true -Dsun.awt.warmup=true " \
"-Xbootclasspath/a:/usr/lib/jvm/java-7-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-7-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-7-oracle/jre/lib/plugin.jar " \
"-Xms12m -Xmx384m -Djnlpx.jvm=/usr/lib/jvm/java-7-oracle/jre/bin/java " \
"com.sun.javaws.Main Notepad.jnlp";
trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
g_free (trimmed);
g_object_unref (matcher);
}
static void
test_autostart_desktop_file_user (void)
{
gchar *file = g_build_filename (g_get_user_config_dir(), "autostart", "foo-app.desktop", NULL);
g_assert (is_autostart_desktop_file (file));
g_free (file);
file = g_build_filename (g_get_user_config_dir(), "foo-app.desktop", NULL);
g_assert (!is_autostart_desktop_file (file));
g_free (file);
}
static void
test_autostart_desktop_file_system (void)
{
const gchar * const * data_dirs = g_get_system_config_dirs ();
gint i;
for (i = 0; data_dirs[i]; ++i)
{
gchar *file = g_build_filename (data_dirs[i], "autostart", "foo-app.desktop", NULL);
g_assert (is_autostart_desktop_file (file));
g_free (file);
file = g_build_filename (data_dirs[i], "foo-app.desktop", NULL);
g_assert (!is_autostart_desktop_file (file));
g_free (file);
}
}
static void
test_get_view_by_path (void)
{
BamfMatcher *matcher;
BamfLegacyScreen *screen;
BamfLegacyWindowTest *lwin;
BamfApplication *app;
BamfWindow *win;
GList *app_children;
guint32 xid;
screen = bamf_legacy_screen_get_default();
matcher = bamf_matcher_get_default ();
cleanup_matcher_tables (matcher);
export_matcher_on_bus (matcher);
xid = g_random_int ();
lwin = bamf_legacy_window_test_new (xid, "Window", NULL, NULL);
_bamf_legacy_screen_open_test_window (screen, lwin);
app = bamf_matcher_get_application_by_xid (matcher, xid);
const char *app_path = bamf_view_get_path (BAMF_VIEW (app));
g_assert (app == BAMF_APPLICATION (bamf_matcher_get_view_by_path (matcher, app_path)));
app_children = bamf_view_get_children (BAMF_VIEW (app));
g_assert (app_children);
win = BAMF_WINDOW (app_children->data);
const char *win_path = bamf_view_get_path (BAMF_VIEW (win));
g_assert (win == BAMF_WINDOW (bamf_matcher_get_view_by_path (matcher, win_path)));
g_object_unref (matcher);
g_object_unref (screen);
}
static void
test_class_valid_name (void)
{
BamfMatcher *matcher;
matcher = bamf_matcher_get_default ();
g_assert (bamf_matcher_is_valid_class_name (matcher, "any-good-class"));
g_assert (!bamf_matcher_is_valid_class_name (matcher, "sun-awt-X11-XFramePeer"));
g_assert (!bamf_matcher_is_valid_class_name (matcher, "net-sourceforge-jnlp-runtime-Boot"));
g_assert (!bamf_matcher_is_valid_class_name (matcher, "com-sun-javaws-Main"));
g_assert (!bamf_matcher_is_valid_class_name (matcher, "VCLSalFrame"));
g_object_unref (matcher);
}
/* Initialize test suite */
void
test_matcher_create_suite (GDBusConnection *connection)
{
gdbus_connection = connection;
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/AutostartDesktopFile/User", test_autostart_desktop_file_user);
g_test_add_func (DOMAIN"/AutostartDesktopFile/System", test_autostart_desktop_file_system);
g_test_add_func (DOMAIN"/ClassValidName", test_class_valid_name);
g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
g_test_add_func (DOMAIN"/GetViewByPath", test_get_view_by_path);
g_test_add_func (DOMAIN"/LoadDesktopFile", test_load_desktop_file);
g_test_add_func (DOMAIN"/LoadDesktopFile/Autostart", test_load_desktop_file_autostart);
g_test_add_func (DOMAIN"/LoadDesktopFile/NoDisplay/SameID", test_load_desktop_file_no_display_has_lower_prio_same_id);
g_test_add_func (DOMAIN"/LoadDesktopFile/NoDisplay/DifferentID", test_load_desktop_file_no_display_has_lower_prio_different_id);
g_test_add_func (DOMAIN"/Matching/Application/DesktopLess", test_match_desktopless_application);
g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);
g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
g_test_add_func (DOMAIN"/Matching/Application/UnityControlCenter", test_match_unity_control_center_panels);
g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/HintIngored", test_match_javaws_windows_hint_ignored);
g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart/NoDesktopMatch", test_match_javaws_windows_no_desktop_match);
g_test_add_func (DOMAIN"/Matching/Application/Qml/NoDesktopMatch", test_match_qml_app_no_desktop);
g_test_add_func (DOMAIN"/Matching/Application/Qml/DesktopMatch", test_match_qml_app_desktop);
g_test_add_func (DOMAIN"/Matching/Application/DesktopFileHintExec", test_match_desktop_file_hint_exec);
g_test_add_func (DOMAIN"/Matching/Application/DesktopFileHintExec/Invalid", test_match_desktop_file_hint_exec_invalid);
g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
g_test_add_func (DOMAIN"/Matching/Windows/Transient", test_match_transient_windows);
g_test_add_func (DOMAIN"/OpenWindows", test_open_windows);
g_test_add_func (DOMAIN"/RegisterDesktopForPid", test_register_desktop_for_pid);
g_test_add_func (DOMAIN"/RegisterDesktopForPid/BigNumber", test_register_desktop_for_pid_big_number);
g_test_add_func (DOMAIN"/RegisterDesktopForPid/Autostart", test_register_desktop_for_pid_autostart);
g_test_add_func (DOMAIN"/RegisterDesktopForPid/Display", test_register_desktop_for_pid_display);
g_test_add_func (DOMAIN"/RegisterDesktopForPid/NoDisplay", test_register_desktop_for_pid_nodisplay);
}
./tests/Makefile.am 0000644 0000156 0000165 00000000201 12704153435 014270 0 ustar jenkins jenkins SUBDIRS = \
bamfdaemon \
libbamf \
$(NULL)
EXTRA_DIST = \
data \
run-xvfb.sh \
gtester2xunit.py \
gtester.xsl \
$(NULL)
./tests/functional/ 0000755 0000156 0000165 00000000000 12704153435 014405 5 ustar jenkins jenkins ./tests/gtester2xunit.py 0000755 0000156 0000165 00000003710 12704153435 015450 0 ustar jenkins jenkins #! /usr/bin/python
from argparse import ArgumentParser
import libxslt
import libxml2
import sys
import os
XSL_TRANSFORM='/usr/share/gtester2xunit/gtester.xsl'
def transform_file(input_filename, output_filename, xsl_file):
gtester = libxml2.parseFile(xsl_file)
style = libxslt.parseStylesheetDoc(gtester)
doc = libxml2.parseFile(input_filename)
result = style.applyStylesheet(doc, None)
result.saveFormatFile(filename=output_filename, format=True)
def get_output_filename(input_filename):
filename, extension = os.path.splitext(input_filename)
return '{filename}-xunit{extension}'.format(filename=filename,
extension=extension)
def main():
parser = ArgumentParser(
description="Simple utility that converts xml output of " +
"gtester to xunit output for jenkins")
parser.add_argument('-o', '--output',
help="Write output to specified file instead of default")
parser.add_argument('-x', '--xsl',
help="xsl file that should be used for the transformation")
parser.add_argument('-i', '--in-place',
help="Write the ouput to the original file (i.e. replace " +
"the original xml)",
action='store_true',
default=False)
parser.add_argument('files', metavar='FILE', type=str, nargs='+',
help="file(s) to transform to xunit format")
args = vars(parser.parse_args())
for input_filename in args['files']:
if not args['output']:
if args['in_place']:
output_filename = input_filename
else:
output_filename = get_output_filename(input_filename)
else:
output_filename = args['output']
if not args['xsl']:
xsl = XSL_TRANSFORM
else:
xsl = args['xsl']
transform_file(input_filename, output_filename, xsl)
sys.exit(main())
# vim: set syntex=python:
./tests/libbamf/ 0000755 0000156 0000165 00000000000 12704153435 013637 5 ustar jenkins jenkins ./tests/libbamf/test-application.c 0000644 0000156 0000165 00000010636 12704153435 017271 0 ustar jenkins jenkins /*
* Copyright (C) 2013 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 Marco Trevisan (Treviño)
*
*/
#include
#include
#include
#include
#include "bamf-view-private.h"
#define DATA_DIR TESTDIR "/data"
void ignore_fatal_errors (void);
static void
test_allocation (void)
{
BamfApplication *application;
/* Check it allocates */
application = g_object_new (BAMF_TYPE_APPLICATION, NULL);
g_assert (BAMF_IS_APPLICATION (application));
g_object_unref (application);
}
static void
test_favorite_invalid_desktop (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/invalid-type.desktop");
g_assert (!BAMF_IS_APPLICATION (application));
application = bamf_application_new_favorite (DATA_DIR"/not-existing-file.desktop");
g_assert (!BAMF_IS_APPLICATION (application));
ignore_fatal_errors ();
application = bamf_application_new_favorite (NULL);
g_assert (!BAMF_IS_APPLICATION (application));
}
static void
test_favorite_valid_desktop_file_system (void)
{
BamfApplication *application;
const gchar *desktop_file = DATA_DIR"/unity-control-center.desktop";
application = bamf_application_new_favorite (desktop_file);
g_assert_cmpstr (bamf_application_get_desktop_file (application), ==, desktop_file);
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "System Settings");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "preferences-system");
g_assert_cmpstr (bamf_application_get_application_type (application), ==, "system");
g_object_unref (application);
}
static void
test_favorite_full_name (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/full-name.desktop");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "Full Application Name");
g_object_unref (application);
}
static void
test_favorite_no_icon (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/no-icon.desktop");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, BAMF_APPLICATION_DEFAULT_ICON);
g_object_unref (application);
}
static void
test_favorite_mime_type_filled (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (TESTDIR"/data/mime-types.desktop");
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert_cmpuint (g_strv_length (mimes), ==, 7);
g_assert_cmpstr (mimes[0], ==, "text/plain");
g_assert_cmpstr (mimes[1], ==, "text/x-chdr");
g_assert_cmpstr (mimes[2], ==, "text/x-csrc");
g_assert_cmpstr (mimes[3], ==, "text/html");
g_assert_cmpstr (mimes[4], ==, "text/css");
g_assert_cmpstr (mimes[5], ==, "text/x-diff");
g_assert_cmpstr (mimes[6], ==, "application/xml");
g_assert_cmpstr (mimes[7], ==, NULL);
g_strfreev (mimes);
g_object_unref (application);
}
static void
test_favorite_mime_type_empty (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (TESTDIR"/data/test-bamf-app.desktop");
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert (!mimes);
g_object_unref (application);
}
void
test_application_create_suite (void)
{
#define DOMAIN "/Application"
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/Favorite/DesktopFile/Invalid", test_favorite_invalid_desktop);
g_test_add_func (DOMAIN"/Favorite/DesktopFile/Valid/System", test_favorite_valid_desktop_file_system);
g_test_add_func (DOMAIN"/Favorite/FullName", test_favorite_full_name);
g_test_add_func (DOMAIN"/Favorite/NoIcon", test_favorite_no_icon);
g_test_add_func (DOMAIN"/Favorite/MimeType/Filled", test_favorite_mime_type_filled);
g_test_add_func (DOMAIN"/Favorite/MimeType/Empty", test_favorite_mime_type_empty);
}
./tests/libbamf/Makefile.am 0000644 0000156 0000165 00000001145 12704153435 015674 0 ustar jenkins jenkins TESTDIR=$(shell realpath $(abs_top_srcdir)/tests)
noinst_PROGRAMS = \
test-libbamf
test_libbamf_SOURCES = \
test-libbamf.c \
test-application.c \
test-matcher.c \
$(NULL)
test_libbamf_CFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib/libbamf \
-I$(top_builddir)/lib/libbamf \
-DTESTDIR=\""$(TESTDIR)"\" \
$(COVERAGE_CFLAGS) \
$(GCC_FLAGS) \
$(GLIB_CFLAGS) \
$(NULL)
test_libbamf_LDADD = \
$(top_builddir)/lib/libbamf/libbamf$(LIBBAMF_VER).la \
$(COVERAGE_LDFLAGS) \
$(GLIB_LIBS) \
$(NULL)
TEST_BINARY = test-libbamf
include $(top_srcdir)/tests/Makefile.am.gtests
./tests/libbamf/test-libbamf.c 0000644 0000156 0000165 00000003043 12704153435 016354 0 ustar jenkins jenkins /*
* Copyright (C) 2013 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 Marco Trevisan
*
*/
#include
#include
#include
#include
#include
void test_matcher_create_suite (void);
void test_application_create_suite (void);
static gboolean
not_fatal_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data)
{
// Don't crash if used
return FALSE;
}
void
ignore_fatal_errors (void)
{
g_test_log_set_fatal_handler (not_fatal_log_handler, NULL);
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
const gchar *old_path = g_getenv ("PATH");
gchar *new_path = g_strdup_printf (TESTDIR"/data/bin:%s", old_path);
g_setenv ("BAMF_TEST_MODE", "TRUE", TRUE);
g_setenv ("PATH", new_path, TRUE);
g_free (new_path);
test_matcher_create_suite ();
test_application_create_suite ();
return g_test_run ();
}
./tests/libbamf/test-matcher.c 0000644 0000156 0000165 00000004140 12704153435 016402 0 ustar jenkins jenkins /*
* Copyright (C) 2009-2013 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: Marco Trevisan (Treviño)
* Neil Jagdish Patel
*
*/
#include
#include
#include "libbamf.h"
void ignore_fatal_errors (void);
static void
test_allocation (void)
{
BamfMatcher *matcher;
ignore_fatal_errors();
matcher = bamf_matcher_get_default ();
g_assert (BAMF_IS_MATCHER (matcher));
g_object_unref (matcher);
}
static void
test_singleton (void)
{
BamfMatcher *matcher_1, *matcher_2;
ignore_fatal_errors();
matcher_1 = bamf_matcher_get_default ();
g_assert (BAMF_IS_MATCHER (matcher_1));
matcher_2 = bamf_matcher_get_default ();
g_assert (matcher_1 == matcher_2);
g_assert_cmpuint (G_OBJECT (matcher_1)->ref_count, ==, 2);
g_object_unref (matcher_2);
g_object_unref (matcher_1);
}
static void
test_singleton_after_unref (void)
{
BamfMatcher *matcher_old, *matcher_new;
ignore_fatal_errors();
matcher_old = bamf_matcher_get_default ();
g_object_add_weak_pointer (G_OBJECT (matcher_old), (gpointer*) &matcher_old);
g_object_unref (matcher_old);
g_assert (matcher_old == NULL);
matcher_new = bamf_matcher_get_default ();
g_assert (matcher_old != matcher_new);
g_object_unref (matcher_new);
}
void
test_matcher_create_suite (void)
{
#define DOMAIN "/Matcher"
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/Singleton", test_singleton);
g_test_add_func (DOMAIN"/SingletonUnref", test_singleton_after_unref);
}
./tests/data/ 0000755 0000156 0000165 00000000000 12704153435 013154 5 ustar jenkins jenkins ./tests/data/libreoffice-math.desktop 0000644 0000156 0000165 00000000203 12704153435 017742 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-math
Type=Application
Exec=libreoffice --math %U
Name=LibreOffice Math
./tests/data/libreoffice-base.desktop 0000644 0000156 0000165 00000000203 12704153435 017723 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-base
Type=Application
Exec=libreoffice --base %U
Name=LibreOffice Base
./tests/data/libreoffice-draw.desktop 0000644 0000156 0000165 00000000203 12704153435 017746 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-draw
Type=Application
Exec=libreoffice --draw %U
Name=LibreOffice Draw
./tests/data/bamf-qml-app.desktop 0000644 0000156 0000165 00000000237 12704153435 017023 0 ustar jenkins jenkins [Desktop Entry]
Name=Bamf Qml APP
Exec=qmlscene bamf_qml_app.qml
Icon=bamf-qml-icon
Terminal=false
Type=Application
StartupNotify=true
OnlyShowIn=GNOME;Unity;
./tests/data/invalid-type.desktop 0000644 0000156 0000165 00000000111 12704153435 017145 0 ustar jenkins jenkins [Desktop Entry]
Name=Invalid Type
Exec=gedit
Terminal=false
Type=FooType
./tests/data/no-icon.desktop 0000644 0000156 0000165 00000000230 12704153435 016104 0 ustar jenkins jenkins [Desktop Entry]
Name=Default
Comment=Interactive viewer for a Default icon!
Exec=gedit
Terminal=false
Type=Application
Categories=GTK;Science;Graphics;
./tests/data/libreoffice-writer.desktop 0000644 0000156 0000165 00000000211 12704153435 020324 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-writer
Type=Application
Exec=libreoffice --writer %U
Name=LibreOffice Writer
./tests/data/libreoffice-startcenter.desktop 0000644 0000156 0000165 00000000176 12704153435 021360 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-startcenter
Type=Application
Exec=libreoffice %U
Name=LibreOffice
./tests/data/icedtea-netx-javaws.desktop 0000644 0000156 0000165 00000000454 12704153435 020415 0 ustar jenkins jenkins [Desktop Entry]
Name=IcedTea Java Web Start
Name[fi]=IcedTea Java - Web Start
Comment=IcedTea Java Web Start
Comment[fi]=IcedTea Java - Web Start
Exec=/usr/bin/javaws %u
Terminal=false
Type=Application
Icon=javaws
Categories=Application;Network;
MimeType=application/x-java-jnlp-file;
NoDisplay=true
./tests/data/ubuntu-web-app.desktop 0000644 0000156 0000165 00000000172 12704153435 017422 0 ustar jenkins jenkins [Desktop Entry]
Name=Ubuntu
Type=Application
Icon=ubuntu-icon
Exec=unity-webapps-runner -n 'AbCdEfGh=' -d 'ubuntu.com' %u
./tests/data/test-bamf-app.desktop 0000644 0000156 0000165 00000000170 12704153435 017205 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Name=TestBamfApp
Type=Application
Exec=test-bamf-app
Icon=bamf
StartupWMClass=test_bamf_app
./tests/data/icons/ 0000755 0000156 0000165 00000000000 12704153435 014267 5 ustar jenkins jenkins ./tests/data/icons/python2.7.png 0000644 0000156 0000165 00000000000 12704153435 016533 0 ustar jenkins jenkins ./tests/data/icons/test-bamf-pixmap.png 0000644 0000156 0000165 00000000000 12704153435 020141 0 ustar jenkins jenkins ./tests/data/icons/test-bamf-icon.png 0000644 0000156 0000165 00000000000 12704153435 017573 0 ustar jenkins jenkins ./tests/data/icons/python.png 0000644 0000156 0000165 00000000000 12704153435 016304 0 ustar jenkins jenkins ./tests/data/bin/ 0000755 0000156 0000165 00000000000 12704153435 013724 5 ustar jenkins jenkins ./tests/data/bin/qmlscene 0000755 0000156 0000165 00000000000 12704153435 015447 0 ustar jenkins jenkins ./tests/data/bin/gedit 0000755 0000156 0000165 00000000046 12704153435 014746 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/bin/unity-webapps-runner 0000755 0000156 0000165 00000000046 12704153435 017770 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/bin/test-bamf-app 0000755 0000156 0000165 00000000046 12704153435 016312 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/bin/unity-control-center 0000755 0000156 0000165 00000000046 12704153435 017756 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/bin/libreoffice 0000755 0000156 0000165 00000000046 12704153435 016123 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/bin/mime-test-text-editor 0000755 0000156 0000165 00000000046 12704153435 020024 0 ustar jenkins jenkins #!/bin/sh
echo "Just a fake program"
./tests/data/no-display/ 0000755 0000156 0000165 00000000000 12704153435 015233 5 ustar jenkins jenkins ./tests/data/no-display/test-bamf-app.desktop 0000644 0000156 0000165 00000000207 12704153435 021265 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Name=TestBamfApp
Type=Application
Exec=test-bamf-app
Icon=bamf
NoDisplay=true
StartupWMClass=test_bamf_app
./tests/data/libreoffice-impress.desktop 0000644 0000156 0000165 00000000214 12704153435 020475 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-impress
Type=Application
Exec=libreoffice --impress %U
Name=LibreOffice Impress
./tests/data/icon.desktop 0000644 0000156 0000165 00000000211 12704153435 015471 0 ustar jenkins jenkins [Desktop Entry]
Name=Test Bamf App with Icon
Exec=test-bamf-app
Icon=test-bamf-icon
Terminal=false
Type=Application
Categories=Graphics;
./tests/data/full-name.desktop 0000644 0000156 0000165 00000000203 12704153435 016422 0 ustar jenkins jenkins [Desktop Entry]
Type=Application
Name=FullName
X-GNOME-FullName=Full Application Name
Exec=gedit
Terminal=false
Icon=full-name-icon ./tests/data/libreoffice-calc.desktop 0000644 0000156 0000165 00000000203 12704153435 017713 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Terminal=false
Icon=libreoffice-calc
Type=Application
Exec=libreoffice --calc %U
Name=LibreOffice Calc
./tests/data/test-bamf-app-display.desktop 0000644 0000156 0000165 00000000170 12704153435 020650 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Name=TestBamfApp
Type=Application
Exec=test-bamf-app
Icon=bamf
StartupWMClass=test_bamf_app
./tests/data/unity-display-panel.desktop 0000644 0000156 0000165 00000000765 12704153435 020467 0 ustar jenkins jenkins [Desktop Entry]
Name=Displays
Comment=Change resolution and position of monitors and projectors
Exec=unity-control-center display
Icon=unity-display-panel
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-Unity-Settings-Panel;
OnlyShowIn=Unity;
X-Unity-Settings-Panel=display
# Translators: those are keywords for the display control-center panel
Keywords=Panel;Projector;xrandr;Screen;Resolution;Refresh;
X-Ubuntu-Gettext-Domain=unity-control-center
./tests/data/test-bamf-app-no-display.desktop 0000644 0000156 0000165 00000000207 12704153435 021263 0 ustar jenkins jenkins [Desktop Entry]
Version=1.0
Name=TestBamfApp
Type=Application
Exec=test-bamf-app
Icon=bamf
NoDisplay=true
StartupWMClass=test_bamf_app
./tests/data/unity-control-center.desktop 0000644 0000156 0000165 00000000420 12704153435 020647 0 ustar jenkins jenkins [Desktop Entry]
Name=System Settings
Icon=preferences-system
Exec=unity-control-center --overview
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;System;
OnlyShowIn=Unity;
Keywords=Preferences;Settings;
X-Ubuntu-Gettext-Domain=unity-control-center
./tests/data/mime-types.desktop 0000644 0000156 0000165 00000000434 12704153435 016641 0 ustar jenkins jenkins #!/usr/bin/env xdg-open
[Desktop Entry]
Name=Mime Text Editor
GenericName=Text Editor
Exec=mime-test-text-editor %F
Terminal=false
Type=Application
MimeType=text/plain;text/x-chdr;text/x-csrc;text/html;text/css;text/x-diff;application/xml;
Categories=TextEditor;Development;Utility;
./tests/data/unity-mouse-panel.desktop 0000644 0000156 0000165 00000000754 12704153435 020150 0 ustar jenkins jenkins [Desktop Entry]
Name=Mouse & Touchpad
Comment=Set your mouse and touchpad preferences
Exec=unity-control-center mouse
Icon=input-mouse
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-Unity-Settings-Panel;
OnlyShowIn=Unity;
X-Unity-Settings-Panel=mouse
# Translators: those are keywords for the mouse and touchpad control-center panel
Keywords=Trackpad;Pointer;Click;Tap;Double;Button;Trackball;
X-Ubuntu-Gettext-Domain=unity-control-center
./tests/gtester.xsl 0000644 0000156 0000165 00000006151 12704153435 014453 0 ustar jenkins jenkins
g_test
./src/ 0000755 0000156 0000165 00000000000 12704153447 011673 5 ustar jenkins jenkins ./src/bamf-matcher.c 0000644 0000156 0000165 00000264022 12704153435 014370 0 ustar jenkins jenkins /*
* 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: Jason Smith
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "config.h"
#include "bamf-matcher.h"
#include "bamf-matcher-private.h"
#include "bamf-application.h"
#include "bamf-tab.h"
#include "bamf-window.h"
#include "bamf-legacy-screen.h"
#include
#define BAMF_INDEX_NAME "bamf-2.index"
G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON);
#define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_MATCHER, BamfMatcherPrivate))
enum
{
FAVORITES_CHANGED,
LAST_SIGNAL,
};
typedef enum
{
VIEW_ADDED = 0,
VIEW_REMOVED
} ViewChangeType;
static BamfMatcher *static_matcher;
static guint matcher_signals[LAST_SIGNAL] = { 0 };
// Prefixes to be ignored in exec strings
const gchar* EXEC_BAD_PREFIXES[] =
{
"^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$", "^cli$",
"^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d(\\.\\d)?)?$", "^(ba)?sh$",
"^perl$", "^env$", "^xdg-open$", "^qmlscene$", "^qmlviewer$",
"^unity-webapps-runner$", "^webapp-container$",
/* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt\\.jar$",
"^com\\.sun\\.javaws\\.Main$", "^deploy\\.jar$"
};
// Sufixes to be ignored in exec strings
const gchar* EXEC_BAD_SUFIXES = "(\\.bin|\\.py|\\.pl|\\.qml)$";
// Prefixes that must be considered starting point of exec strings
const gchar* EXEC_GOOD_PREFIXES[] =
{
"^unity-control-center$", "^libreoffice$", "^ooffice$", "^wine$", "^steam$",
"^sol$"
};
// These class names are ignored as matching values
const gchar * CLASS_BAD_VALUES[] =
{
"sun-awt-X11-XFramePeer", "net-sourceforge-jnlp-runtime-Boot",
"com-sun-javaws-Main", "VCLSalFrame"
};
const gchar * EXEC_DESKTOP_FILE_OVERRIDE = "--desktop_file_hint";
static void
on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *last;
g_return_if_fail (BAMF_IS_MATCHER (matcher));
g_return_if_fail (BAMF_IS_VIEW (view));
priv = matcher->priv;
if (BAMF_IS_APPLICATION (view))
{
/* Do some handy short circuiting so we can assume a signal
* will be generated at the end of this
*/
if (!active && priv->active_app != view)
return;
if (active && priv->active_app == view)
return;
last = priv->active_app;
if (active)
priv->active_app = view;
else
priv->active_app = NULL;
g_signal_emit_by_name (matcher, "active-application-changed",
BAMF_IS_VIEW (last) ? bamf_view_get_path (BAMF_VIEW (last)) : "",
BAMF_IS_VIEW (priv->active_app) ? bamf_view_get_path (BAMF_VIEW (priv->active_app)) : "");
}
else if (BAMF_IS_WINDOW (view))
{
/* Do some handy short circuiting so we can assume a signal
* will be generated at the end of this
*/
if (!active && priv->active_win != view)
return;
if (active && priv->active_win == view)
return;
last = priv->active_win;
if (active)
priv->active_win = view;
else
priv->active_win = NULL;
g_signal_emit_by_name (matcher, "active-window-changed",
BAMF_IS_VIEW (last) ? bamf_view_get_path (BAMF_VIEW (last)) : "",
BAMF_IS_VIEW (priv->active_win) ? bamf_view_get_path (BAMF_VIEW (priv->active_win)) : "");
}
}
static void bamf_matcher_unregister_view (BamfMatcher *self, BamfView *view);
BamfApplication *
bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file)
{
GList *l;
BamfView *view;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
if (!desktop_file || desktop_file[0] == '\0')
return NULL;
for (l = self->priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view))
continue;
BamfApplication *app = BAMF_APPLICATION (view);
const gchar *app_desktop;
app_desktop = bamf_application_get_desktop_file (app);
if (g_strcmp0 (desktop_file, app_desktop) == 0)
{
return app;
}
}
return NULL;
}
BamfApplication *
bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid)
{
GList *l;
BamfView *view;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
for (l = self->priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view))
continue;
if (bamf_application_manages_xid (BAMF_APPLICATION (view), xid))
{
return BAMF_APPLICATION (view);
}
}
return NULL;
}
BamfView *
bamf_matcher_get_view_by_path (BamfMatcher *self, const char *view_path)
{
GList *l;
BamfView *view;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
for (l = self->priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_VIEW (view))
continue;
if (g_strcmp0 (bamf_view_get_path (view), view_path) == 0)
{
return view;
}
}
return NULL;
}
static gboolean
emit_paths_changed (gpointer user_data)
{
BamfMatcher *matcher;
BamfMatcherPrivate *priv;
GHashTableIter iter;
guint ht_size;
ViewChangeType change_type;
gpointer key, value;
gchar **opened_apps, **closed_apps;
gint i, j;
g_return_val_if_fail (BAMF_IS_MATCHER (user_data), FALSE);
matcher = (BamfMatcher*) user_data;
priv = matcher->priv;
ht_size = g_hash_table_size (priv->opened_closed_paths_table);
/* these will end with NULL pointer */
opened_apps = g_new0 (gchar*, ht_size+1);
closed_apps = g_new0 (gchar*, ht_size+1);
i = 0;
j = 0;
g_hash_table_iter_init (&iter, priv->opened_closed_paths_table);
while (g_hash_table_iter_next (&iter, &key, &value))
{
change_type = (ViewChangeType) GPOINTER_TO_UINT (value);
if (change_type == VIEW_ADDED)
opened_apps[i++] = (gchar*) key;
else
closed_apps[j++] = (gchar*) key;
}
/* the strings are owned by the hashtable, so emit the signal and clear
* the hashtable then */
g_signal_emit_by_name (matcher, "running-applications-changed",
opened_apps, closed_apps);
g_hash_table_remove_all (priv->opened_closed_paths_table);
g_free (closed_apps);
g_free (opened_apps);
priv->dispatch_changes_id = 0;
return FALSE;
}
static void
bamf_matcher_prepare_path_change (BamfMatcher *self, const gchar *desktop_file, ViewChangeType change_type)
{
BamfMatcherPrivate *priv;
BamfApplication *app;
if (desktop_file == NULL) return;
g_return_if_fail (BAMF_IS_MATCHER (self));
priv = self->priv;
/* the app was already running (ADDED) / had more instances which are still
* there (REMOVED) */
app = bamf_matcher_get_application_by_desktop_file (self, desktop_file);
if (BAMF_IS_APPLICATION (app) && bamf_view_is_running (BAMF_VIEW (app)))
{
return;
}
if (!priv->opened_closed_paths_table)
{
priv->opened_closed_paths_table = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free, NULL);
}
g_hash_table_insert (priv->opened_closed_paths_table,
g_strdup (desktop_file), GUINT_TO_POINTER (change_type));
if (priv->dispatch_changes_id == 0)
{
priv->dispatch_changes_id = g_timeout_add (500, emit_paths_changed, self);
}
}
static gboolean
bamf_matcher_is_view_registered (BamfMatcher *self, BamfView *view)
{
g_return_val_if_fail (BAMF_IS_MATCHER (self), FALSE);
g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
/* Instead of looping over the self->priv->views list, we can safely assume
* that if a view is not registered then its path is NULL */
return (bamf_view_get_path (view) != NULL);
}
static void
bamf_matcher_register_view_stealing_ref (BamfMatcher *self, BamfView *view)
{
const char *path, *type;
GDBusConnection *connection;
GDBusInterfaceSkeleton *dbus_interface = G_DBUS_INTERFACE_SKELETON (self);
connection = g_dbus_interface_skeleton_get_connection (dbus_interface);
path = bamf_view_export_on_bus (view, connection);
type = bamf_view_get_view_type (view);
g_signal_connect_swapped (G_OBJECT (view), "closed-internal",
(GCallback) bamf_matcher_unregister_view, self);
g_signal_connect (G_OBJECT (view), "active-changed",
(GCallback) on_view_active_changed, self);
if (BAMF_IS_APPLICATION (view))
{
bamf_matcher_prepare_path_change (self,
bamf_application_get_desktop_file (BAMF_APPLICATION (view)), VIEW_ADDED);
}
// This steals the reference of the view
self->priv->views = g_list_prepend (self->priv->views, view);
g_signal_emit_by_name (self, "view-opened", path, type);
// trigger manually since this is already active
if (bamf_view_is_active (view))
on_view_active_changed (view, TRUE, self);
}
static void
bamf_matcher_unregister_view (BamfMatcher *self, BamfView *view)
{
const char * path;
const char * type;
path = bamf_view_get_path (view);
type = bamf_view_get_view_type (view);
g_signal_emit_by_name (self, "view-closed", path, type);
g_signal_handlers_disconnect_by_data (G_OBJECT (view), self);
if (BAMF_IS_APPLICATION (view))
{
bamf_matcher_prepare_path_change (self,
bamf_application_get_desktop_file (BAMF_APPLICATION (view)),
VIEW_REMOVED);
}
if (self->priv->active_app == view)
self->priv->active_app = NULL;
if (self->priv->active_win == view)
self->priv->active_win = NULL;
GList *listed_view = g_list_find (self->priv->views, view);
if (listed_view)
{
self->priv->views = g_list_delete_link (self->priv->views, listed_view);
g_object_unref (view);
}
}
gboolean
bamf_matcher_is_valid_process_prefix (BamfMatcher *self, const char *process_name)
{
GRegex *regex;
gint i;
g_return_val_if_fail (BAMF_IS_MATCHER (self), TRUE);
if (!process_name || *process_name == '\0')
return FALSE;
for (i = 0; i < self->priv->bad_prefixes->len; ++i)
{
regex = g_array_index (self->priv->bad_prefixes, GRegex *, i);
if (g_regex_match (regex, process_name, 0, NULL))
{
return FALSE;
}
}
return TRUE;
}
/* Attempts to return the binary name for a particular execution string */
char *
bamf_matcher_get_trimmed_exec (BamfMatcher * self, const char * exec_string)
{
gchar *result = NULL, *part, *tmp;
gchar **parts;
gint i, j, parts_size;
gboolean bad_prefix;
gboolean good_prefix = FALSE;
gboolean double_parsed = FALSE;
GRegex *regex;
if (!exec_string || exec_string[0] == '\0')
return NULL;
if (!g_shell_parse_argv (exec_string, &parts_size, &parts, NULL))
return g_strdup (exec_string);
for (i = 0; i < parts_size; ++i)
{
part = parts[i];
if (*part == '%' || *part == '$' || g_utf8_strrchr (part, -1, '='))
continue;
if (i+1 < parts_size && g_strcmp0 (parts[i], EXEC_DESKTOP_FILE_OVERRIDE) == 0)
{
/* Skip if the .desktop file is overridden using the exec parameter */
++i;
continue;
}
if (*part != '-' || good_prefix)
{
if (!result)
{
tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR);
if (tmp)
part = tmp + 1;
}
if (good_prefix)
{
tmp = g_strconcat (result, " ", part, NULL);
g_free (result);
result = tmp;
}
else
{
for (j = 0; j < self->priv->good_prefixes->len; j++)
{
regex = g_array_index (self->priv->good_prefixes, GRegex *, j);
if (g_regex_match (regex, part, 0, NULL))
{
good_prefix = TRUE;
result = g_ascii_strdown (part, -1);
break;
}
}
if (good_prefix)
continue;
bad_prefix = !bamf_matcher_is_valid_process_prefix (self, part);
if (!bad_prefix)
{
if (!double_parsed && g_utf8_strrchr (part, -1, ' '))
{
/* If the current exec_string has an empty char,
* we double check it again to parse scripts:
* For example strings like 'sh -c "foo || bar"' */
gchar **old_parts = parts;
if (g_shell_parse_argv (part, &parts_size, &parts, NULL))
{
// Make the loop to restart!
g_strfreev (old_parts);
i = -1;
continue;
}
double_parsed = TRUE;
}
result = g_ascii_strdown (part, -1);
break;
}
}
}
}
if (!result)
{
if (parts_size > 0)
{
tmp = g_utf8_strrchr (parts[0], -1, G_DIR_SEPARATOR);
if (tmp)
exec_string = tmp + 1;
}
result = g_strdup (exec_string);
}
else
{
tmp = result;
regex = g_regex_new (EXEC_BAD_SUFIXES, 0, 0, NULL);
result = g_regex_replace_literal (regex, result, -1, 0, "", 0, NULL);
g_free (tmp);
g_regex_unref (regex);
}
g_strfreev (parts);
return result;
}
char *
get_exec_overridden_desktop_file (const char *exec_string)
{
gchar *result = NULL;
gchar **parts;
gint i, parts_size;
if (!exec_string || exec_string[0] == '\0')
return result;
if (!g_shell_parse_argv (exec_string, &parts_size, &parts, NULL))
return result;
for (i = 0; i < parts_size; ++i)
{
if (i+1 < parts_size && g_strcmp0 (parts[i], EXEC_DESKTOP_FILE_OVERRIDE) == 0)
{
if (g_str_has_suffix (parts[i+1], ".desktop") &&
g_file_test (parts[i+1], G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR))
{
result = g_strdup (parts[i+1]);
break;
}
}
}
g_strfreev (parts);
return result;
}
static GList *
pid_parent_tree (BamfMatcher *self, guint pid)
{
BamfMatcherPrivate *priv;
GList *tree, *l;
guint known_pid;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
priv = self->priv;
tree = g_list_append (NULL, GUINT_TO_POINTER (pid));
glibtop_proc_uid buf;
glibtop_get_proc_uid (&buf, pid);
pid = buf.ppid;
while (pid > 1)
{
for (l = priv->known_pids; l; l = l->next)
{
/* ensure we dont match onto a terminal by mistake */
known_pid = GPOINTER_TO_UINT (l->data);
if (known_pid == pid)
return tree;
}
tree = g_list_prepend (tree, GUINT_TO_POINTER (pid));
glibtop_proc_uid buf;
glibtop_get_proc_uid (&buf, pid);
pid = buf.ppid;
}
return g_list_reverse (tree);
}
static gboolean
is_desktop_folder_item (const char *desktop_file_path, gssize max_len)
{
gsize len;
const char *desktop_folder;
g_return_val_if_fail (desktop_file_path, FALSE);
if (max_len > 0)
{
len = max_len;
}
else
{
char *tmp;
tmp = strrchr (desktop_file_path, G_DIR_SEPARATOR);
g_return_val_if_fail (tmp, FALSE);
len = tmp - desktop_file_path;
}
desktop_folder = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
if (strncmp (desktop_folder, desktop_file_path, len) == 0)
return TRUE;
return FALSE;
}
static gboolean
is_no_display_desktop (BamfMatcher *self, const gchar *desktop_path)
{
g_return_val_if_fail (BAMF_IS_MATCHER (self), FALSE);
if (!desktop_path || desktop_path[0] == '\0')
return FALSE;
GList *list = self->priv->no_display_desktop;
return g_list_find_custom (list, desktop_path, (GCompareFunc) g_strcmp0) != NULL;
}
static GList *
get_last_no_display_desktop_in_list (BamfMatcher *self, GList *desktop_list)
{
GList *last, *l;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
last = NULL;
for (l = desktop_list; l; l = l->next)
{
char *desktop_path = l->data;
if (is_no_display_desktop (self, desktop_path))
{
last = l;
break;
}
}
return last;
}
static void
insert_data_into_tables (BamfMatcher *self,
const char *data,
const char *exec,
const char *desktop_id,
gboolean no_display,
GHashTable *desktop_file_table,
GHashTable *desktop_id_table)
{
GList *file_list, *id_list, *last, *l;
char *datadup;
g_return_if_fail (exec);
g_return_if_fail (desktop_id);
file_list = g_hash_table_lookup (desktop_file_table, exec);
id_list = g_hash_table_lookup (desktop_id_table, desktop_id);
if (g_list_find_custom (file_list, data, (GCompareFunc) g_strcmp0) &&
g_list_find_custom (id_list, data, (GCompareFunc) g_strcmp0))
{
return;
}
datadup = g_strdup (data);
if (no_display)
{
self->priv->no_display_desktop = g_list_prepend (self->priv->no_display_desktop, datadup);
}
/* order so that items whose desktop_id == exec string are first in the list */
if (g_strcmp0 (exec, desktop_id) == 0 || is_desktop_folder_item (datadup, -1))
{
last = NULL;
for (l = file_list; l; l = l->next)
{
char *dpath;
char *dname_start, *dname_end;
size_t len;
dpath = l->data;
dname_start = strrchr (dpath, G_DIR_SEPARATOR);
if (!dname_start)
{
continue;
}
dname_start++;
dname_end = strrchr (dname_start, '.');
len = dname_end - dname_start;
if (!dname_end || len < 1)
{
continue;
}
if ((strncmp (desktop_id, dname_start, len) != 0 || is_no_display_desktop (self, dpath)) &&
!is_desktop_folder_item (dpath, (dname_start - dpath - 1)))
{
last = l;
break;
}
}
file_list = g_list_insert_before (file_list, last, datadup);
}
else
{
last = NULL;
if (!no_display)
last = get_last_no_display_desktop_in_list (self, file_list);
file_list = g_list_insert_before (file_list, last, datadup);
}
last = NULL;
if (!no_display)
last = get_last_no_display_desktop_in_list (self, id_list);
id_list = g_list_insert_before (id_list, last, datadup);
g_hash_table_insert (desktop_file_table, g_strdup (exec), file_list);
g_hash_table_insert (desktop_id_table, g_strdup (desktop_id), id_list);
}
static void
insert_desktop_file_class_into_table (BamfMatcher *self,
const char *desktop_file,
GHashTable *desktop_class_table)
{
GKeyFile *desktop_keyfile;
char *class;
g_return_if_fail (desktop_file);
desktop_keyfile = g_key_file_new ();
if (g_key_file_load_from_file (desktop_keyfile, desktop_file, G_KEY_FILE_NONE,
NULL))
{
class = g_key_file_get_string (desktop_keyfile,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS,
NULL);
if (class)
g_hash_table_insert (desktop_class_table, g_strdup (desktop_file), class);
g_key_file_free (desktop_keyfile);
}
}
static void
load_desktop_file_to_table (BamfMatcher * self,
const char *file,
GHashTable *desktop_file_table,
GHashTable *desktop_id_table,
GHashTable *desktop_class_table)
{
GDesktopAppInfo *desktop_file;
gboolean no_display;
const char *current_desktop;
char *exec;
char *path;
GString *desktop_id; /* is ok... really */
g_return_if_fail (BAMF_IS_MATCHER (self));
desktop_file = g_desktop_app_info_new_from_filename (file);
if (!G_IS_APP_INFO (desktop_file))
{
return;
}
current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (current_desktop && !g_desktop_app_info_get_show_in (desktop_file, current_desktop))
{
g_object_unref (desktop_file);
return;
}
exec = g_strdup (g_app_info_get_commandline (G_APP_INFO (desktop_file)));
if (!exec || exec[0] == '\0')
{
g_object_unref (desktop_file);
if (exec)
{
g_free (exec);
}
return;
}
/**
* Set of nasty hacks which should be removed some day. We wish to keep the full exec
* strings so we can do nasty matching hacks later. A very very evil thing indeed. However this
* helps hack around applications that run in the same process cross radically different instances.
* A better solution needs to be thought up, however at this time it is not known.
**/
char *tmp = bamf_matcher_get_trimmed_exec (self, exec);
g_free (exec);
exec = tmp;
path = g_path_get_basename (file);
desktop_id = g_string_new (path);
g_free (path);
desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
no_display = g_desktop_app_info_get_nodisplay (desktop_file);
insert_data_into_tables (self, file, exec, desktop_id->str, no_display, desktop_file_table, desktop_id_table);
insert_desktop_file_class_into_table (self, file, desktop_class_table);
g_free (exec);
g_string_free (desktop_id, TRUE);
g_object_unref (desktop_file);
}
static void
load_directory_to_table (BamfMatcher * self,
const char *directory,
GHashTable *desktop_file_table,
GHashTable *desktop_id_table,
GHashTable *desktop_class_table)
{
GFile *dir;
GFileEnumerator *enumerator;
GFileInfo *info;
const char *name;
char *path;
dir = g_file_new_for_path (directory);
enumerator = g_file_enumerate_children (dir,
"standard::*",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL,
NULL);
if (!enumerator)
return;
info = g_file_enumerator_next_file (enumerator, NULL, NULL);
for (; info; info = g_file_enumerator_next_file (enumerator, NULL, NULL))
{
name = g_file_info_get_name (info);
path = g_build_filename (directory, name, NULL);
if (g_str_has_suffix (name, ".desktop"))
load_desktop_file_to_table (self,
path,
desktop_file_table,
desktop_id_table,
desktop_class_table);
g_free (path);
g_object_unref (info);
}
g_object_unref (enumerator);
g_object_unref (dir);
}
static void
load_index_file_to_table (BamfMatcher * self,
const char *index_file,
GHashTable *desktop_file_table,
GHashTable *desktop_id_table,
GHashTable *desktop_class_table)
{
GFile *file;
GFileInputStream *stream;
GDataInputStream *input;
char *line;
char *directory;
const char *current_desktop;
gsize length;
file = g_file_new_for_path (index_file);
g_return_if_fail (file);
stream = g_file_read (file, NULL, NULL);
if (!stream)
{
g_object_unref (file);
return;
}
length = 0;
current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
directory = g_path_get_dirname (index_file);
input = g_data_input_stream_new (G_INPUT_STREAM (stream));
if (current_desktop && current_desktop[0] == '\0')
current_desktop = NULL;
while ((line = g_data_input_stream_read_line (input, &length, NULL, NULL)))
{
char *exec;
char *filename;
const char *class;
const char *show_in;
GString *desktop_id;
gboolean no_display;
/* Order is: 0 Desktop-Id, 1 Exec, 2 class, 3 ShowIn, 4 NoDisplay */
gchar **parts = g_strsplit (line, "\t", 5);
show_in = parts[3];
if (current_desktop && show_in && show_in[0] != '\0')
{
gchar **sub_parts = g_strsplit (show_in, ";", -1);
gboolean found_current = FALSE;
int i = 0;
for (i = 0; sub_parts[i]; ++i)
{
if (g_ascii_strcasecmp (sub_parts[i], current_desktop) == 0)
{
found_current = TRUE;
break;
}
}
g_strfreev (sub_parts);
if (!found_current)
{
length = 0;
g_strfreev (parts);
continue;
}
}
char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]);
g_free (parts[1]);
parts[1] = tmp;
exec = parts[1];
filename = g_build_filename (directory, parts[0], NULL);
desktop_id = g_string_new (parts[0]);
g_string_truncate (desktop_id, desktop_id->len - 8);
no_display = FALSE;
if (parts[4] && g_ascii_strcasecmp (parts[4], "true") == 0)
{
no_display = TRUE;
}
insert_data_into_tables (self, filename, exec, desktop_id->str, no_display, desktop_file_table, desktop_id_table);
class = parts[2];
if (class && class[0] != '\0')
{
g_hash_table_insert (desktop_class_table, g_strdup (filename), g_strdup (class));
}
g_string_free (desktop_id, TRUE);
g_free (line);
g_free (filename);
g_strfreev (parts);
length = 0;
}
g_object_unref (input);
g_object_unref (stream);
g_object_unref (file);
g_free (directory);
}
static GList * get_directory_tree_list (GList *) G_GNUC_WARN_UNUSED_RESULT;
static GList *
get_directory_tree_list (GList *dirs)
{
GList *l;
GFile *file;
GFileEnumerator *enumerator;
GFileInfo *info;
gchar *path, *subpath;
for (l = dirs; l; l = l->next)
{
path = l->data;
file = g_file_new_for_path (path);
if (!g_file_query_exists (file, NULL))
{
g_object_unref (file);
continue;
}
enumerator = g_file_enumerate_children (file,
"standard::*",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL,
NULL);
if (!enumerator)
continue;
info = g_file_enumerator_next_file (enumerator, NULL, NULL);
while (info)
{
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{
/* append after the current list item for non-recursive recursion love
* and to keep the priorities (hierarchy) of the .desktop directories.
*/
subpath = g_build_filename (path, g_file_info_get_name (info), NULL);
dirs = g_list_insert_before (dirs, l->next, subpath);
}
g_object_unref (info);
info = g_file_enumerator_next_file (enumerator, NULL, NULL);
}
g_object_unref (enumerator);
g_object_unref (file);
}
return dirs;
}
static GList * list_prepend_desktop_file_env_directories (GList *, const gchar *) G_GNUC_WARN_UNUSED_RESULT;
static GList *
list_prepend_desktop_file_env_directories (GList *dirs, const gchar *varname)
{
g_return_val_if_fail (varname, dirs);
const gchar *env;
char *path;
char **data_dirs = NULL;
char **data;
env = g_getenv (varname);
if (env)
{
data_dirs = g_strsplit (env, ":", 0);
for (data = data_dirs; data && *data; data++)
{
path = g_build_filename (*data, "applications", NULL);
if (g_file_test (path, G_FILE_TEST_IS_DIR) &&
!g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0))
{
dirs = g_list_prepend (dirs, path);
}
else
{
g_free (path);
}
}
if (data_dirs)
g_strfreev (data_dirs);
}
return dirs;
}
static GList *
get_desktop_file_directories (BamfMatcher *self)
{
GList *dirs = NULL;
char *path;
dirs = list_prepend_desktop_file_env_directories (dirs, "XDG_DATA_DIRS");
if (!g_list_find_custom (dirs, "/usr/share/applications", (GCompareFunc) g_strcmp0))
dirs = g_list_prepend (dirs, g_strdup ("/usr/share/applications"));
if (!g_list_find_custom (dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0))
dirs = g_list_prepend (dirs, g_strdup ("/usr/local/share/applications"));
dirs = list_prepend_desktop_file_env_directories (dirs, "XDG_DATA_HOME");
/* If XDG_DATA_HOME doesn't exist, we need to track .local or the home itself! */
path = g_build_filename (g_get_home_dir (), ".local/share/applications", NULL);
if (!g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0))
dirs = g_list_prepend (dirs, path);
else
g_free (path);
/* include subdirs */
dirs = get_directory_tree_list (dirs);
/* Include also the user desktop folder, but without its subfolders */
dirs = g_list_prepend (dirs, g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)));
return dirs;
}
static gint
compare_sub_values (gconstpointer desktop_path, gconstpointer desktop_file)
{
return !g_str_has_prefix (desktop_file, desktop_path);
}
static void
hash_table_remove_sub_values (GHashTable *htable, GCompareFunc compare_func,
GFreeFunc free_func, gpointer target, gboolean search_all)
{
g_return_if_fail (htable);
g_return_if_fail (compare_func);
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init (&iter, htable);
while (g_hash_table_iter_next (&iter, &key, &value))
{
GList *list, *l;
gboolean found;
list = value;
found = FALSE;
l = list;
while (l)
{
GList *next = l->next;
if (compare_func (target, l->data) == 0)
{
found = TRUE;
if (!l->prev && !l->next)
{
if (free_func)
g_list_free_full (list, free_func);
else
g_list_free (list);
g_hash_table_iter_remove (&iter);
next = NULL;
break;
}
else
{
if (free_func)
free_func (l->data);
/* If the target is the first element of the list (and thanks to
* the previous check we're also sure that it's not the only one),
* simply switch it with its follower, not to change the first
* pointer and the hash table value for key
*/
if (l == list)
{
l->data = next->data;
l = next;
next = list;
}
list = g_list_delete_link (list, l);
}
if (!search_all)
break;
}
l = next;
}
if (found && !search_all)
break;
}
}
static gboolean
hash_table_compare_sub_values (gpointer desktop_path, gpointer desktop_class, gpointer target_path)
{
return !compare_sub_values (target_path, desktop_path);
}
static void fill_desktop_file_table (BamfMatcher *, GList *, GHashTable *, GHashTable *, GHashTable *);
static void
on_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent type, BamfMatcher *self)
{
char *path;
const char *monitored_dir;
GFileType filetype;
g_return_if_fail (G_IS_FILE_MONITOR (monitor));
g_return_if_fail (G_IS_FILE (file));
g_return_if_fail (BAMF_IS_MATCHER (self));
if (type != G_FILE_MONITOR_EVENT_CREATED &&
type != G_FILE_MONITOR_EVENT_DELETED &&
type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
return;
path = g_file_get_path (file);
filetype = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
monitored_dir = g_object_get_data (G_OBJECT (monitor), "root");
if (!g_str_has_suffix (path, ".desktop") &&
filetype != G_FILE_TYPE_DIRECTORY &&
type != G_FILE_MONITOR_EVENT_DELETED)
{
g_free(path);
return;
}
if (type == G_FILE_MONITOR_EVENT_DELETED ||
type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
{
if (g_str_has_suffix (path, ".desktop"))
{
/* Remove all the .desktop file references from the hash tables.
* Free the string itself only on the 2nd pass (tables share the same
* string instance)
*/
hash_table_remove_sub_values (self->priv->desktop_id_table,
(GCompareFunc) g_strcmp0, NULL, path, FALSE);
hash_table_remove_sub_values (self->priv->desktop_file_table,
(GCompareFunc) g_strcmp0, g_free, path, FALSE);
g_hash_table_remove (self->priv->desktop_class_table, path);
}
else if (g_strcmp0 (monitored_dir, path) == 0)
{
/* Remove all the references to the .desktop files placed in subfolders
* of the current path. Free the strings itself only on the 2nd pass
* (as before, the tables share the same string instance)
*/
char *prefix = g_strconcat (path, G_DIR_SEPARATOR_S, NULL);
hash_table_remove_sub_values (self->priv->desktop_id_table,
compare_sub_values, NULL, prefix, TRUE);
hash_table_remove_sub_values (self->priv->desktop_file_table,
compare_sub_values, g_free, prefix, TRUE);
g_hash_table_foreach_remove (self->priv->desktop_class_table,
hash_table_compare_sub_values, prefix);
g_signal_handlers_disconnect_by_func (monitor, on_monitor_changed, self);
self->priv->monitors = g_list_remove (self->priv->monitors, monitor);
g_object_unref (monitor);
g_free (prefix);
}
}
if (type == G_FILE_MONITOR_EVENT_CREATED ||
type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
{
if (filetype == G_FILE_TYPE_DIRECTORY)
{
const char *desktop_dir;
desktop_dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
if (g_strcmp0 (monitored_dir, desktop_dir) != 0)
{
GList *dirs = NULL;
dirs = g_list_prepend (dirs, g_strdup (path));
dirs = get_directory_tree_list (dirs);
fill_desktop_file_table (self, dirs,
self->priv->desktop_file_table,
self->priv->desktop_id_table,
self->priv->desktop_class_table);
g_list_free_full (dirs, g_free);
}
}
else if (filetype != G_FILE_TYPE_UNKNOWN)
{
bamf_matcher_load_desktop_file (self, path);
}
}
g_free (path);
}
static void
bamf_matcher_add_new_monitored_directory (BamfMatcher * self, const gchar *directory)
{
g_return_if_fail (BAMF_IS_MATCHER (self));
GFile *file;
GFileMonitor *monitor;
GError *error = NULL;
file = g_file_new_for_path (directory);
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, &error);
if (error)
{
g_message ("Error monitoring %s: %s\n", directory, error->message);
g_error_free (error);
g_object_unref (file);
return;
}
g_file_monitor_set_rate_limit (monitor, 1000);
g_object_set_data_full (G_OBJECT (monitor), "root", g_strdup (directory), g_free);
g_signal_connect (monitor, "changed", (GCallback) on_monitor_changed, self);
self->priv->monitors = g_list_prepend (self->priv->monitors, monitor);
g_object_unref (file);
}
static void
fill_desktop_file_table (BamfMatcher * self,
GList *directories,
GHashTable *desktop_file_table,
GHashTable *desktop_id_table,
GHashTable *desktop_class_table)
{
g_return_if_fail (BAMF_IS_MATCHER (self));
GList *l;
char *directory;
char *bamf_file;
for (l = directories; l; l = l->next)
{
directory = l->data;
if (!g_file_test (directory, G_FILE_TEST_IS_DIR))
continue;
bamf_matcher_add_new_monitored_directory (self, directory);
bamf_file = g_build_filename (directory, BAMF_INDEX_NAME, NULL);
if (g_file_test (bamf_file, G_FILE_TEST_EXISTS))
{
load_index_file_to_table (self, bamf_file, desktop_file_table,
desktop_id_table, desktop_class_table);
}
else
{
load_directory_to_table (self, directory, desktop_file_table,
desktop_id_table, desktop_class_table);
}
g_free (bamf_file);
}
}
static void
create_desktop_file_table (BamfMatcher * self,
GHashTable **desktop_file_table,
GHashTable **desktop_id_table,
GHashTable **desktop_class_table)
{
g_return_if_fail (BAMF_IS_MATCHER (self));
GList *directories;
*desktop_file_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
NULL);
*desktop_id_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
NULL);
*desktop_class_table =
g_hash_table_new_full ((GHashFunc) g_str_hash,
(GEqualFunc) g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
directories = get_desktop_file_directories (self);
fill_desktop_file_table (self, directories, *desktop_file_table,
*desktop_id_table, *desktop_class_table);
g_list_free_full (directories, g_free);
}
static GList *
bamf_matcher_possible_applications_for_window_process (BamfMatcher *self, BamfLegacyWindow *window)
{
BamfMatcherPrivate *priv;
GList *result = NULL, *table_list, *l;
const char *exec_string;
char *trimmed;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
priv = self->priv;
exec_string = bamf_legacy_window_get_exec_string (window);
if (exec_string)
{
trimmed = bamf_matcher_get_trimmed_exec (self, exec_string);
if (trimmed)
{
if (trimmed[0] != '\0')
{
table_list = g_hash_table_lookup (priv->desktop_file_table, trimmed);
for (l = table_list; l; l = l->next)
{
result = g_list_prepend (result, g_strdup (l->data));
}
}
g_free (trimmed);
}
}
if (result)
{
result = g_list_reverse (result);
return result;
}
gchar *proc_name = bamf_legacy_window_get_process_name (window);
if (bamf_matcher_is_valid_process_prefix (self, proc_name))
{
table_list = g_hash_table_lookup (priv->desktop_file_table, proc_name);
for (l = table_list; l; l = l->next)
{
result = g_list_prepend (result, g_strdup (l->data));
}
}
g_free (proc_name);
result = g_list_reverse (result);
return result;
}
static gboolean
is_libreoffice_window (BamfLegacyWindow * window)
{
const char *class_name = bamf_legacy_window_get_class_name (window);
if (!class_name)
return FALSE;
return (g_ascii_strncasecmp (class_name, "libreoffice", 11) == 0 ||
g_ascii_strncasecmp (class_name, "openoffice", 10) == 0);
}
static gboolean
is_web_app_window (BamfLegacyWindow *window)
{
const char *window_class = bamf_legacy_window_get_class_name (window);
const char *instance_name = bamf_legacy_window_get_class_instance_name (window);
// Chrome/Chromium uses url wm_class strings to represent its web apps (--app mode).
// These apps will still have the same parent pid and hints as the main chrome
// window, so we skip the hint check.
// We can tell a window is a chrome web app window if its instance name is
// not google-chrome but its window class is Google-chrome
// We can tell a window is chromium web app window if its instance name is
// not chromium-browser but its window class is Chromium Browser
gboolean valid_app = FALSE;
if (instance_name && window_class)
{
if (g_strcmp0 (window_class, "Google-chrome") == 0 &&
g_strcmp0 (instance_name, "google-chrome") != 0 &&
!g_str_has_prefix (instance_name, "Google-chrome"))
{
valid_app = TRUE;
}
else if (g_strcmp0 (window_class, "Chromium-browser") == 0 &&
g_strcmp0 (instance_name, "chromium-browser") != 0 &&
!g_str_has_prefix (instance_name, "Chromium-browser"))
{
valid_app = TRUE;
}
}
return valid_app;
}
static gboolean
is_javaws_window (BamfLegacyWindow *window)
{
const char *window_class = bamf_legacy_window_get_class_name (window);
if (g_strcmp0 (window_class, "net-sourceforge-jnlp-runtime-Boot") == 0 ||
g_strcmp0 (window_class, "com-sun-javaws-Main") == 0)
{
return TRUE;
}
return FALSE;
}
static gboolean
bamf_matcher_window_skips_hint_set (BamfMatcher *self, BamfLegacyWindow *window)
{
gboolean skip_hint_set;
g_return_val_if_fail (BAMF_IS_MATCHER (self), TRUE);
skip_hint_set = is_libreoffice_window (window) || is_web_app_window (window) || is_javaws_window (window);
return skip_hint_set;
}
static GList *
bamf_matcher_get_class_matching_desktop_files (BamfMatcher *self, const gchar *class_name)
{
GList* desktop_files = NULL;
gpointer key;
gpointer value;
GHashTableIter iter;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
g_hash_table_iter_init (&iter, self->priv->desktop_class_table);
while (g_hash_table_iter_next (&iter, &key, &value))
{
gchar* desktop_file = g_strdup (key);
gchar* desktop_class = value;
if (g_strcmp0 (desktop_class, class_name) == 0)
{
desktop_files = g_list_prepend (desktop_files, desktop_file);
}
}
return desktop_files;
}
static gboolean
bamf_matcher_has_instance_class_desktop_file (BamfMatcher *self, const gchar *class_name)
{
gpointer key;
gpointer value;
GHashTableIter iter;
g_return_val_if_fail (BAMF_IS_MATCHER (self), FALSE);
g_hash_table_iter_init (&iter, self->priv->desktop_class_table);
while (g_hash_table_iter_next (&iter, &key, &value))
{
gchar* desktop_class = value;
if (g_strcmp0 (desktop_class, class_name) == 0)
{
return TRUE;
}
}
return FALSE;
}
gboolean
bamf_matcher_is_valid_class_name (BamfMatcher *self, const char *class_name)
{
int i;
g_return_val_if_fail (BAMF_IS_MATCHER (self), FALSE);
if (!class_name)
return TRUE;
for (i = 0; i < G_N_ELEMENTS (CLASS_BAD_VALUES); ++i)
{
if (g_strcmp0 (class_name, CLASS_BAD_VALUES[i]) == 0)
return FALSE;
}
return TRUE;
}
static GList *
bamf_matcher_possible_applications_for_window (BamfMatcher *self,
BamfWindow *bamf_window,
const char **target_class_out)
{
BamfMatcherPrivate *priv;
BamfLegacyWindow *window;
GList *desktop_files = NULL, *l;
char *app_id;
char *desktop_file = NULL;
const char *desktop_class = NULL;
const char *class_name = NULL;
const char *instance_name = NULL;
const char *target_class = NULL;
gboolean filter_by_wmclass = FALSE;
g_return_val_if_fail (BAMF_IS_WINDOW (bamf_window), NULL);
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
priv = self->priv;
window = bamf_window_get_window (bamf_window);
desktop_file = bamf_legacy_window_get_hint (window, _BAMF_DESKTOP_FILE);
class_name = bamf_legacy_window_get_class_name (window);
instance_name = bamf_legacy_window_get_class_instance_name (window);
if (!bamf_matcher_is_valid_class_name (self, class_name))
class_name = NULL;
if (!bamf_matcher_is_valid_class_name (self, instance_name))
instance_name = NULL;
target_class = instance_name;
filter_by_wmclass = bamf_matcher_has_instance_class_desktop_file (self, target_class);
if (!filter_by_wmclass)
{
if (is_web_app_window (window))
{
// This ensures that a new application is created even for unknown webapps
filter_by_wmclass = TRUE;
}
else
{
target_class = class_name;
filter_by_wmclass = bamf_matcher_has_instance_class_desktop_file (self, target_class);
}
}
if (desktop_file)
{
desktop_class = bamf_matcher_get_desktop_file_class (self, desktop_file);
if ((!filter_by_wmclass && !desktop_class) || g_strcmp0 (desktop_class, target_class) == 0)
{
desktop_files = g_list_prepend (desktop_files, desktop_file);
}
else
{
g_free (desktop_file);
}
}
else
{
const char *exec_string = bamf_legacy_window_get_exec_string (window);
desktop_file = get_exec_overridden_desktop_file (exec_string);
if (desktop_file)
{
desktop_files = g_list_prepend (desktop_files, desktop_file);
}
else
{
app_id = bamf_legacy_window_get_hint (window, _GTK_APPLICATION_ID);
if (app_id)
{
for (l = g_hash_table_lookup (priv->desktop_id_table, app_id); l; l = l->next)
{
desktop_file = l->data;
desktop_class = bamf_matcher_get_desktop_file_class (self, desktop_file);
if ((!filter_by_wmclass && !desktop_class) || g_strcmp0 (desktop_class, target_class) == 0)
{
desktop_files = g_list_prepend (desktop_files, g_strdup (desktop_file));
}
}
g_free (app_id);
}
}
}
desktop_file = NULL;
if (!desktop_files)
{
if (class_name)
{
char *window_class_down = g_ascii_strdown (class_name, -1);
l = g_hash_table_lookup (priv->desktop_id_table, window_class_down);
g_free (window_class_down);
for (; l; l = l->next)
{
desktop_file = l->data;
if (desktop_file)
{
desktop_class = bamf_matcher_get_desktop_file_class (self, desktop_file);
if ((!filter_by_wmclass && !desktop_class) || g_strcmp0 (desktop_class, target_class) == 0)
{
if (!g_list_find_custom (desktop_files, desktop_file,
(GCompareFunc) g_strcmp0))
{
desktop_files = g_list_prepend (desktop_files, g_strdup (desktop_file));
}
}
}
}
desktop_files = g_list_reverse (desktop_files);
}
GList *pid_list = bamf_matcher_possible_applications_for_window_process (self, window);
/* Append these files to the end to give preference to class_name style picking.
This style of matching is prefered and used by GNOME Shell however does not work
very well in practice, thus requiring the fallback here */
for (l = pid_list; l; l = l->next)
{
desktop_file = l->data;
if (g_list_find_custom (desktop_files, desktop_file, (GCompareFunc) g_strcmp0))
{
g_free (desktop_file);
}
else
{
gboolean append = FALSE;
if (target_class)
{
desktop_class = bamf_matcher_get_desktop_file_class (self, desktop_file);
if ((!filter_by_wmclass && !desktop_class) || g_strcmp0 (desktop_class, target_class) == 0)
{
append = TRUE;
}
}
else
{
append = TRUE;
}
if (append)
{
/* If we're adding a .desktop file stored in the desktop folder,
give it the priority it should have. */
GList *last = NULL;
if (is_desktop_folder_item (desktop_file, -1))
{
GList *ll;
for (ll = desktop_files; ll; ll = ll->next)
{
if (!is_desktop_folder_item (ll->data, -1))
{
last = ll;
break;
}
}
}
desktop_files = g_list_insert_before (desktop_files, last, desktop_file);
}
else
{
g_free (desktop_file);
}
}
}
g_list_free (pid_list);
}
if (!desktop_files && filter_by_wmclass)
{
desktop_files = bamf_matcher_get_class_matching_desktop_files (self, target_class);
}
if (target_class_out)
{
*target_class_out = target_class;
}
return desktop_files;
}
static BamfApplication *
bamf_matcher_get_application_for_window (BamfMatcher *self,
BamfWindow *bamf_window)
{
GList *possible_apps, *l;
BamfLegacyWindow *window;
const gchar *win_class_name;
const gchar *target_class = NULL;
const gchar *app_class = NULL;
const gchar *app_desktop = NULL;
BamfApplication *app = NULL, *best = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
g_return_val_if_fail (BAMF_IS_WINDOW (bamf_window), NULL);
window = bamf_window_get_window (bamf_window);
if (bamf_legacy_window_get_window_type (window) != BAMF_WINDOW_NORMAL)
{
BamfLegacyWindow *transient = bamf_legacy_window_get_transient (window);
if (transient)
{
Window xid = bamf_legacy_window_get_xid (transient);
app = bamf_matcher_get_application_by_xid (self, xid);
if (BAMF_IS_APPLICATION (app))
return app;
}
}
win_class_name = bamf_legacy_window_get_class_name (window);
possible_apps = bamf_matcher_possible_applications_for_window (self, bamf_window, &target_class);
app_class = target_class;
/* Loop over every possible desktop file that could match the window, and try
* to reuse an already-opened window that uses it.
* Desktop files are ordered by priority, so we try to use the first possible,
* wm_class matching applications have the priority, btw. */
if (possible_apps)
{
/* primary matching */
for (l = possible_apps; l; l = l->next)
{
const gchar *desktop_file = l->data;
app = bamf_matcher_get_application_by_desktop_file (self, desktop_file);
if (BAMF_IS_APPLICATION (app))
{
const gchar *app_desktop_class;
app_desktop_class = bamf_application_get_wmclass (app);
if (target_class && app_desktop_class && strcasecmp (target_class, app_desktop_class) == 0)
{
best = app;
break;
}
else if (!best)
{
best = app;
}
}
}
/* If a "best" application has been found, we should check again if the
* desktop file that is going to be used is really the best one we have.
* To do this, we compare the window class name with the desktop class
* of both candidates to ensure that really is the best one.
* This is important to avoid that very-similar (which differ only by
* StartupWMClass) running desktop files, would be wrongly used to match
* an incompatible window. */
if (BAMF_IS_APPLICATION (best) && possible_apps)
{
const gchar *best_app_desktop = bamf_application_get_desktop_file (best);
const gchar *best_desktop = possible_apps->data;
if (win_class_name && g_strcmp0 (best_app_desktop, best_desktop) != 0)
{
const gchar *best_app_class;
const gchar *best_desktop_class;
best_app_class = bamf_application_get_wmclass (best);
best_desktop_class = bamf_matcher_get_desktop_file_class (self, best_desktop);
/* We compare the two classes using their "distance" from the
* desidered class value */
if (best_app_class && best_desktop_class)
{
int max_chars = strlen (win_class_name);
int app_diff = strncasecmp (win_class_name, best_app_class, max_chars);
int desktop_diff = strncasecmp (win_class_name, best_desktop_class, max_chars);
if (abs (desktop_diff) < abs (app_diff))
{
best = bamf_matcher_get_application_by_desktop_file (self, best_desktop);
app_desktop = best_desktop;
}
}
}
}
}
else
{
/* secondary matching */
GList *a;
BamfView *view;
const gchar *app_desktop_class;
const char *win_instance_name = bamf_legacy_window_get_class_instance_name (window);
const char *exec_string = bamf_legacy_window_get_exec_string (window);
char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string);
if (trimmed_exec || win_class_name || win_instance_name)
{
for (a = self->priv->views; a; a = a->next)
{
view = a->data;
if (!BAMF_IS_APPLICATION (view))
continue;
app = BAMF_APPLICATION (view);
if (bamf_application_contains_similar_to_window (app, bamf_window))
{
GList *ll;
gboolean found_exec = FALSE;
for (ll = bamf_view_get_children (BAMF_VIEW (app)); ll && !found_exec; ll = ll->next)
{
if (!BAMF_IS_WINDOW (ll->data))
continue;
BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data));
const char *wexec = bamf_legacy_window_get_exec_string (w);
char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec);
if (g_strcmp0 (trimmed_exec, wtrimmed) == 0)
{
best = BAMF_APPLICATION (view);
found_exec = TRUE;
}
g_free (wtrimmed);
}
if (!found_exec)
continue;
app_desktop_class = bamf_application_get_wmclass (app);
if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)
{
best = app;
break;
}
else if (!best)
{
best = app;
}
}
}
}
g_free (trimmed_exec);
}
if (!best)
{
if (app_desktop)
{
best = bamf_application_new_from_desktop_file (app_desktop);
}
else if (possible_apps)
{
best = bamf_application_new_from_desktop_files (possible_apps);
}
else
{
best = bamf_application_new ();
}
bamf_application_set_wmclass (best, app_class);
}
g_list_free_full (possible_apps, g_free);
return best;
}
/* Ensures that the window hint is set if a registered pid matches, and that set window hints
are already known to bamfdaemon */
static void
ensure_window_hint_set (BamfMatcher *self,
BamfLegacyWindow *window)
{
GList *pids, *l;
GHashTable *registered_pids;
char *desktop_file_hint = NULL;
gpointer key;
guint pid;
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
registered_pids = self->priv->registered_pids;
/* Some windows such as web applications shares the pid with their parent
* browser so, we have to ignore them */
if (bamf_matcher_window_skips_hint_set (self, window))
{
return;
}
desktop_file_hint = bamf_legacy_window_get_hint (window, _BAMF_DESKTOP_FILE);
if (desktop_file_hint)
{
/* already set, make sure we know about this
* fact for future windows of this applications */
pid = bamf_legacy_window_get_pid (window);
if (pid > 0)
{
key = GUINT_TO_POINTER (pid);
if (!g_hash_table_lookup (registered_pids, key))
{
g_hash_table_insert (registered_pids, key, g_strdup (desktop_file_hint));
}
}
g_free (desktop_file_hint);
return;
}
pids = pid_parent_tree (self, bamf_legacy_window_get_pid (window));
for (l = pids; l; l = l->next)
{
key = l->data;
desktop_file_hint = g_hash_table_lookup (registered_pids, key);
if (desktop_file_hint != NULL && desktop_file_hint[0] != '\0')
break;
}
g_list_free (pids);
if (desktop_file_hint)
bamf_legacy_window_set_hint (window, _BAMF_DESKTOP_FILE, desktop_file_hint);
}
static void
on_raw_window_class_changed (BamfLegacyWindow *window, BamfMatcher* self)
{
BamfWindow *bamf_win;
BamfApplication *old_app, *new_app;
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
guint xid = bamf_legacy_window_get_xid (window);
old_app = bamf_matcher_get_application_by_xid (self, xid);
if (!old_app)
return;
bamf_win = bamf_application_get_window (old_app, xid);
if (bamf_win)
{
new_app = bamf_matcher_get_application_for_window (self, bamf_win);
if (new_app)
{
if (old_app != new_app)
{
g_object_ref (bamf_win);
bamf_view_remove_child (BAMF_VIEW (old_app), BAMF_VIEW (bamf_win));
if (!bamf_matcher_is_view_registered (self, BAMF_VIEW (new_app)))
{
bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (new_app));
}
bamf_view_add_child (BAMF_VIEW (new_app), BAMF_VIEW (bamf_win));
g_object_unref (bamf_win);
}
else
{
if (!bamf_matcher_is_view_registered (self, BAMF_VIEW (new_app)))
{
/* This is probably never happening, but just in case... */
g_object_unref (new_app);
}
}
}
}
}
static void
on_raw_window_closed (BamfLegacyWindow *window, BamfMatcher* self)
{
g_signal_handlers_disconnect_by_data (window, self);
}
static void
handle_raw_window (BamfMatcher *self, BamfLegacyWindow *window)
{
BamfWindow *bamf_win;
BamfApplication *bamf_app;
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
g_signal_connect (window, "class-changed", G_CALLBACK (on_raw_window_class_changed), self);
g_signal_connect (window, "closed", G_CALLBACK (on_raw_window_closed), self);
guint pid = bamf_legacy_window_get_pid (window);
if (pid > 1 && !g_list_find (self->priv->known_pids, GUINT_TO_POINTER (pid)))
self->priv->known_pids = g_list_prepend (self->priv->known_pids, GUINT_TO_POINTER (pid));
ensure_window_hint_set (self, window);
/* We need to make our objects for bus export, the quickest way to do this, though not
* always the best is to simply go window by window creating new applications as needed.
*/
bamf_win = bamf_window_new (window);
bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamf_win));
bamf_app = bamf_matcher_get_application_for_window (self, bamf_win);
if (!bamf_matcher_is_view_registered (self, BAMF_VIEW (bamf_app)))
{
bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamf_app));
}
bamf_view_add_child (BAMF_VIEW (bamf_app), BAMF_VIEW (bamf_win));
}
static char *
get_unity_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
{
const gchar *role;
GList *list;
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
role = bamf_legacy_window_get_role (window);
if (role)
{
gchar *exec = g_strconcat ("unity-control-center ", role, NULL);
list = g_hash_table_lookup (self->priv->desktop_file_table, exec);
g_free (exec);
}
if (!role || !list)
{
list = g_hash_table_lookup (self->priv->desktop_id_table, "unity-control-center");
}
return (list ? (char *) list->data : NULL);
}
static void
on_unity_control_center_window_role_changed (BamfLegacyWindow *window, BamfMatcher* self)
{
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
char *old_hint;
const char *new_hint;
old_hint = bamf_legacy_window_get_hint (window, _BAMF_DESKTOP_FILE);
new_hint = get_unity_control_center_window_hint (self, window);
if (new_hint && g_strcmp0 (new_hint, old_hint) != 0)
{
bamf_legacy_window_reopen (window);
}
g_free (old_hint);
}
static void
handle_window_opening (BamfLegacyScreen *screen, const gchar *desktop_id, BamfMatcher *self)
{
bamf_matcher_set_starting_desktop_file (self, desktop_id, TRUE);
}
static void
handle_window_opening_finished (BamfLegacyScreen *screen, const gchar *desktop_id, BamfMatcher *self)
{
bamf_matcher_set_starting_desktop_file (self, desktop_id, FALSE);
}
static void
handle_window_opened (BamfLegacyScreen * screen, BamfLegacyWindow * window, BamfMatcher *self)
{
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
BamfWindowType win_type = bamf_legacy_window_get_window_type (window);
if (win_type == BAMF_WINDOW_DESKTOP)
{
BamfWindow *bamfwindow = bamf_window_new (window);
bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamfwindow));
return;
}
if (is_libreoffice_window (window))
{
if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR)
{
return;
}
}
else if (g_strcmp0 (bamf_legacy_window_get_class_name (window), "Unity-control-center") == 0)
{
char *old_hint = bamf_legacy_window_get_hint (window, _BAMF_DESKTOP_FILE);
const char *new_hint = get_unity_control_center_window_hint (self, window);
if (new_hint && g_strcmp0 (old_hint, new_hint) != 0)
{
bamf_legacy_window_set_hint (window, _BAMF_DESKTOP_FILE, new_hint);
}
g_signal_connect (window, "role-changed", (GCallback) on_unity_control_center_window_role_changed, self);
g_free (old_hint);
}
/* we have a window who is ready to be matched */
handle_raw_window (self, window);
}
static void
handle_stacking_changed (BamfLegacyScreen * screen, BamfMatcher *self)
{
g_signal_emit_by_name (self, "stacking-order-changed");
}
void
bamf_matcher_load_desktop_file (BamfMatcher * self,
const char * desktop_file)
{
GList *vl, *wl;
g_return_if_fail (BAMF_IS_MATCHER (self));
if (is_autostart_desktop_file (desktop_file))
return;
load_desktop_file_to_table (self,
desktop_file,
self->priv->desktop_file_table,
self->priv->desktop_id_table,
self->priv->desktop_class_table);
/* If an application with no .desktop file has windows that matches
* the new added .desktop file, then we try to re-match them.
* We use another list to save the windows that should be re-matched to avoid
* that the list that we're iterating is changed, since reopening a window
* makes it to be removed from the views. */
GList *to_rematch = NULL;
for (vl = self->priv->views; vl; vl = vl->next)
{
if (!BAMF_IS_APPLICATION (vl->data))
continue;
BamfApplication *app = BAMF_APPLICATION (vl->data);
if (!bamf_application_get_desktop_file (app))
{
GList *children = bamf_view_get_children (BAMF_VIEW (app));
for (wl = children; wl; wl = wl->next)
{
if (!BAMF_IS_WINDOW (wl->data))
continue;
BamfWindow *win = BAMF_WINDOW (wl->data);
GList *desktops = bamf_matcher_possible_applications_for_window (self, win, NULL);
if (g_list_find_custom (desktops, desktop_file, (GCompareFunc) g_strcmp0))
{
BamfLegacyWindow *legacy_window = bamf_window_get_window (win);
to_rematch = g_list_prepend (to_rematch, legacy_window);
}
g_list_free_full (desktops, g_free);
}
}
}
for (wl = to_rematch; wl; wl = wl->next)
{
BamfLegacyWindow *legacy_window = BAMF_LEGACY_WINDOW (wl->data);
bamf_legacy_window_reopen (legacy_window);
}
g_list_free (to_rematch);
}
gboolean
is_autostart_desktop_file (const gchar *desktop_file)
{
gchar *data_dir;
gchar *dirname;
gboolean autostart;
gint i;
g_return_val_if_fail (desktop_file, FALSE);
autostart = FALSE;
dirname = g_path_get_dirname (desktop_file);
data_dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL);
if (g_strcmp0 (dirname, data_dir) == 0)
{
autostart = TRUE;
}
g_free (data_dir);
if (!autostart)
{
const gchar * const * data_dirs = g_get_system_config_dirs ();
for (i = 0; data_dirs[i]; ++i)
{
data_dir = g_build_filename (data_dirs[i], "autostart", NULL);
if (g_strcmp0 (dirname, data_dir) == 0)
{
autostart = TRUE;
g_free (data_dir);
break;
}
g_free (data_dir);
}
}
g_free (dirname);
return autostart;
}
gboolean
is_valid_desktop_file (const gchar *desktop_file)
{
if (!desktop_file || desktop_file[0] == '\0')
return FALSE;
if (!g_file_test (desktop_file, G_FILE_TEST_EXISTS))
return FALSE;
return TRUE;
}
gboolean
is_visible_desktop_file (BamfMatcher *self,
const gchar *desktop_file)
{
if (!is_valid_desktop_file (desktop_file))
return FALSE;
if (is_no_display_desktop (self, desktop_file))
return FALSE;
if (is_autostart_desktop_file (desktop_file))
return FALSE;
return TRUE;
}
void
bamf_matcher_register_desktop_file_for_pid (BamfMatcher * self,
const gchar * desktop_file,
guint64 pid)
{
gpointer key;
BamfLegacyScreen *screen;
GList *windows, *pids, *l, *ll;
gboolean matching_window_found;
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (desktop_file);
if (!is_visible_desktop_file (self, desktop_file))
return;
key = GUINT_TO_POINTER (pid);
g_hash_table_insert (self->priv->registered_pids, key, g_strdup (desktop_file));
screen = bamf_legacy_screen_get_default ();
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (screen));
windows = bamf_legacy_screen_get_windows (screen);
matching_window_found = FALSE;
for (l = windows; l; l = l->next)
{
BamfLegacyWindow *window = l->data;
if (!BAMF_IS_LEGACY_WINDOW (window))
continue;
pids = pid_parent_tree (self, bamf_legacy_window_get_pid (window));
for (ll = pids; ll; ll = ll->next)
{
if (pid == GPOINTER_TO_UINT (ll->data))
{
matching_window_found = TRUE;
break;
}
}
g_list_free (pids);
if (matching_window_found)
{
ensure_window_hint_set (self, window);
break;
}
}
}
void
bamf_matcher_set_starting_desktop_file (BamfMatcher *self,
const char *desktop_file,
gboolean starting)
{
BamfApplication *app;
g_return_if_fail (BAMF_IS_MATCHER (self));
g_return_if_fail (desktop_file != NULL);
if (!is_visible_desktop_file (self, desktop_file))
return;
app = bamf_matcher_get_application_by_desktop_file (self, desktop_file);
if (!BAMF_IS_APPLICATION (app) && starting)
{
app = bamf_application_new_from_desktop_file (desktop_file);
if (!bamf_matcher_is_view_registered (self, BAMF_VIEW (app)))
{
bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (app));
}
}
if (BAMF_IS_APPLICATION (app))
{
bamf_view_set_starting (BAMF_VIEW (app), starting);
}
}
const char *
bamf_matcher_get_desktop_file_class (BamfMatcher * self, const char * desktop_file)
{
g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
g_return_val_if_fail (desktop_file, NULL);
return g_hash_table_lookup (self->priv->desktop_class_table, desktop_file);
}
static int
x_error_handler (Display *display, XErrorEvent *event)
{
/* We hardly care, this means one of our get or set property calls didn't work
* while this kind of sucks, it wont effect the running of the program except to
* perhaps reduce the efficiency of the application
*/
return 0;
}
const char *
bamf_matcher_get_active_application (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view))
continue;
if (bamf_view_is_active (view))
{
return bamf_view_get_path (view);
}
}
return "";
}
const char *
bamf_matcher_get_active_window (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_WINDOW (view))
continue;
if (bamf_view_is_active (view))
{
return bamf_view_get_path (view);
}
}
return "";
}
const char *
bamf_matcher_application_for_xid (BamfMatcher *matcher,
guint32 xid)
{
BamfApplication *app;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
app = bamf_matcher_get_application_by_xid (matcher, xid);
if (BAMF_IS_APPLICATION (app))
return bamf_view_get_path (BAMF_VIEW (app));
return "";
}
static gint
compare_windows_by_stack_order (gconstpointer a, gconstpointer b)
{
g_return_val_if_fail (BAMF_IS_WINDOW (a), -1);
g_return_val_if_fail (BAMF_IS_WINDOW (b), 1);
gint idx_a = bamf_window_get_stack_position (BAMF_WINDOW (a));
gint idx_b = bamf_window_get_stack_position (BAMF_WINDOW (b));
return (idx_a < idx_b) ? -1 : 1;
}
GVariant *
bamf_matcher_get_window_stack_for_monitor (BamfMatcher *matcher, gint monitor)
{
GList *l;
GList *windows;
BamfView *view;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
windows = NULL;
for (l = matcher->priv->views; l; l = l->next)
{
if (BAMF_IS_WINDOW (l->data))
{
windows = g_list_insert_sorted (windows, l->data,
compare_windows_by_stack_order);
}
}
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
for (l = windows; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_WINDOW (view))
continue;
if ((monitor >= 0 && bamf_window_get_monitor (BAMF_WINDOW (view)) == monitor) ||
monitor < 0)
{
g_variant_builder_add (&b, "s", bamf_view_get_path (view));
}
}
g_list_free (windows);
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
gboolean
bamf_matcher_application_is_running (BamfMatcher *matcher,
const char *application)
{
BamfApplication *app;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE);
app = bamf_matcher_get_application_by_desktop_file (matcher, application);
if (BAMF_IS_APPLICATION (app))
{
return bamf_view_is_running (BAMF_VIEW (app));
}
return FALSE;
}
GVariant *
bamf_matcher_window_dbus_paths (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_WINDOW (view))
continue;
g_variant_builder_add (&b, "s", bamf_view_get_path (view));
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GVariant *
bamf_matcher_application_dbus_paths (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view))
continue;
g_variant_builder_add (&b, "s", bamf_view_get_path (view));
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
const char *
bamf_matcher_dbus_path_for_application (BamfMatcher *matcher,
const char *application)
{
const char * path = "";
BamfApplication *app;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
app = bamf_matcher_get_application_by_desktop_file (matcher, application);
if (BAMF_IS_APPLICATION (app))
{
return bamf_view_get_path (BAMF_VIEW (app));
}
return path;
}
GList *
bamf_matcher_get_favorites (BamfMatcher *matcher)
{
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
return matcher->priv->favorites;
}
void
bamf_matcher_register_favorites (BamfMatcher *matcher,
const char **favorites)
{
const char *fav;
const char **favs;
BamfMatcherPrivate *priv;
g_return_if_fail (BAMF_IS_MATCHER (matcher));
g_return_if_fail (favorites);
priv = matcher->priv;
for (favs = favorites; *favs; favs++)
{
fav = *favs;
/* ignore things already in the list */
if (g_list_find_custom (priv->favorites, fav, (GCompareFunc) g_strcmp0))
continue;
bamf_matcher_load_desktop_file (matcher, fav);
priv->favorites = g_list_prepend (priv->favorites, g_strdup (fav));
}
g_signal_emit (matcher, matcher_signals[FAVORITES_CHANGED], 0);
}
GVariant *
bamf_matcher_running_application_paths (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view) || !bamf_view_is_running (view))
continue;
g_variant_builder_add (&b, "s", bamf_view_get_path (view));
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GVariant *
bamf_matcher_running_applications_desktop_files (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
GSequence *paths;
GSequenceIter *iter;
const char *desktop_file;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
paths = g_sequence_new (NULL);
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_APPLICATION (view) || !bamf_view_is_running (view))
continue;
desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (view));
if (!desktop_file) continue;
if (g_sequence_lookup (paths, (gpointer) desktop_file,
(GCompareDataFunc) g_strcmp0, NULL) == NULL)
{
g_sequence_insert_sorted (paths, (gpointer) desktop_file,
(GCompareDataFunc) g_strcmp0, NULL);
}
}
iter = g_sequence_get_begin_iter (paths);
while (!g_sequence_iter_is_end (iter))
{
g_variant_builder_add (&b, "s", g_sequence_get (iter));
iter = g_sequence_iter_next (iter);
}
g_sequence_free (paths);
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GVariant *
bamf_matcher_tab_dbus_paths (BamfMatcher *matcher)
{
GList *l;
BamfView *view;
BamfMatcherPrivate *priv;
GVariantBuilder b;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
priv = matcher->priv;
for (l = priv->views; l; l = l->next)
{
view = l->data;
if (!BAMF_IS_TAB (view))
continue;
g_variant_builder_add (&b, "s", bamf_view_get_path (view));
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GVariant *
bamf_matcher_xids_for_application (BamfMatcher *matcher,
const char *application)
{
GVariantBuilder b;
GVariant *xids;
BamfApplication *app;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
xids = NULL;
app = bamf_matcher_get_application_by_desktop_file (matcher, application);
if (BAMF_IS_APPLICATION (app))
{
xids = bamf_application_get_xids (app);
}
if (!xids)
{
g_variant_builder_init (&b, G_VARIANT_TYPE ("(au)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("au"));
g_variant_builder_close (&b);
xids = g_variant_builder_end (&b);
}
return xids;
}
static gboolean
on_dbus_handle_xids_for_application (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
const gchar *application,
BamfMatcher *self)
{
GVariant *xids = bamf_matcher_xids_for_application (self, application);
g_dbus_method_invocation_return_value (invocation, xids);
return TRUE;
}
static gboolean
on_dbus_handle_tab_paths (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
GVariant *tab_paths = bamf_matcher_tab_dbus_paths (self);
g_dbus_method_invocation_return_value (invocation, tab_paths);
return TRUE;
}
static gboolean
on_dbus_handle_application_paths (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
GVariant *app_paths = bamf_matcher_application_dbus_paths (self);
g_dbus_method_invocation_return_value (invocation, app_paths);
return TRUE;
}
static gboolean
on_dbus_handle_window_paths (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
GVariant *win_paths = bamf_matcher_window_dbus_paths (self);
g_dbus_method_invocation_return_value (invocation, win_paths);
return TRUE;
}
static gboolean
on_dbus_handle_running_applications (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
GVariant *running_apps = bamf_matcher_running_application_paths (self);
g_dbus_method_invocation_return_value (invocation, running_apps);
return TRUE;
}
static gboolean
on_dbus_handle_running_applications_desktop_files (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
GVariant *paths = bamf_matcher_running_applications_desktop_files (self);
g_dbus_method_invocation_return_value (invocation, paths);
return TRUE;
}
static gboolean
on_dbus_handle_active_application (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
const gchar *active_app = bamf_matcher_get_active_application (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", active_app));
return TRUE;
}
static gboolean
on_dbus_handle_active_window (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
BamfMatcher *self)
{
const gchar *active_win = bamf_matcher_get_active_window (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", active_win));
return TRUE;
}
static gboolean
on_dbus_handle_application_is_running (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
const gchar *application,
BamfMatcher *self)
{
gboolean is_running = bamf_matcher_application_is_running (self, application);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", is_running));
return TRUE;
}
static gboolean
on_dbus_handle_register_favorites (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
const char **favorites,
BamfMatcher *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_matcher_register_favorites (self, favorites);
return TRUE;
}
static gboolean
on_dbus_handle_path_for_application (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
const gchar *application,
BamfMatcher *self)
{
const gchar *app_path = bamf_matcher_dbus_path_for_application (self, application);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", app_path));
return TRUE;
}
static gboolean
on_dbus_handle_application_for_xid (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
guint xid,
BamfMatcher *self)
{
const gchar *app_path = bamf_matcher_application_for_xid (self, xid);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", app_path));
return TRUE;
}
static gboolean
on_dbus_handle_window_stack_for_monitor (BamfDBusMatcher *interface,
GDBusMethodInvocation *invocation,
gint monitor,
BamfMatcher *self)
{
GVariant *windows = bamf_matcher_get_window_stack_for_monitor (self, monitor);
g_dbus_method_invocation_return_value (invocation, windows);
return TRUE;
}
static void
bamf_matcher_init (BamfMatcher * self)
{
BamfMatcherPrivate *priv;
BamfLegacyScreen *screen;
int i;
priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self);
priv->bad_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *),
G_N_ELEMENTS (EXEC_BAD_PREFIXES));
priv->good_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *),
G_N_ELEMENTS (EXEC_GOOD_PREFIXES));
priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, g_free);
for (i = 0; i < G_N_ELEMENTS (EXEC_BAD_PREFIXES); ++i)
{
GRegex *regex = g_regex_new (EXEC_BAD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL);
g_array_append_val (priv->bad_prefixes, regex);
}
for (i = 0; i < G_N_ELEMENTS (EXEC_GOOD_PREFIXES); ++i)
{
GRegex *regex = g_regex_new (EXEC_GOOD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL);
g_array_append_val (priv->good_prefixes, regex);
}
create_desktop_file_table (self, &(priv->desktop_file_table),
&(priv->desktop_id_table),
&(priv->desktop_class_table));
screen = bamf_legacy_screen_get_default ();
g_signal_connect (G_OBJECT (screen), BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING,
G_CALLBACK (handle_window_opening), self);
g_signal_connect (G_OBJECT (screen), BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_COMPLETED,
G_CALLBACK (handle_window_opening_finished), self);
g_signal_connect (G_OBJECT (screen), BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_CANCELED,
G_CALLBACK (handle_window_opening_finished), self);
g_signal_connect (G_OBJECT (screen), BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENED,
G_CALLBACK (handle_window_opened), self);
g_signal_connect (G_OBJECT (screen), BAMF_LEGACY_SCREEN_SIGNAL_STACKING_CHANGED,
G_CALLBACK (handle_stacking_changed), self);
XSetErrorHandler (x_error_handler);
/* Registering signal callbacks to reply to dbus method calls */
g_signal_connect (self, "handle-xids-for-application",
G_CALLBACK (on_dbus_handle_xids_for_application), self);
g_signal_connect (self, "handle-tab-paths",
G_CALLBACK (on_dbus_handle_tab_paths), self);
g_signal_connect (self, "handle-application-paths",
G_CALLBACK (on_dbus_handle_application_paths), self);
g_signal_connect (self, "handle-window-paths",
G_CALLBACK (on_dbus_handle_window_paths), self);
g_signal_connect (self, "handle-running-applications",
G_CALLBACK (on_dbus_handle_running_applications), self);
g_signal_connect (self, "handle-running-applications-desktop-files",
G_CALLBACK (on_dbus_handle_running_applications_desktop_files), self);
g_signal_connect (self, "handle-active-window",
G_CALLBACK (on_dbus_handle_active_window), self);
g_signal_connect (self, "handle-active-application",
G_CALLBACK (on_dbus_handle_active_application), self);
g_signal_connect (self, "handle-application-is-running",
G_CALLBACK (on_dbus_handle_application_is_running), self);
g_signal_connect (self, "handle-register-favorites",
G_CALLBACK (on_dbus_handle_register_favorites), self);
g_signal_connect (self, "handle-path-for-application",
G_CALLBACK (on_dbus_handle_path_for_application), self);
g_signal_connect (self, "handle-application-for-xid",
G_CALLBACK (on_dbus_handle_application_for_xid), self);
g_signal_connect (self, "handle-window-stack-for-monitor",
G_CALLBACK (on_dbus_handle_window_stack_for_monitor), self);
}
static void
bamf_matcher_dispose (GObject *object)
{
BamfMatcher *self = (BamfMatcher *) object;
BamfMatcherPrivate *priv = self->priv;
while (priv->views)
{
bamf_matcher_unregister_view (self, priv->views->data);
}
G_OBJECT_CLASS (bamf_matcher_parent_class)->dispose (object);
}
static void
bamf_matcher_finalize (GObject *object)
{
BamfMatcher *self = (BamfMatcher *) object;
BamfMatcherPrivate *priv = self->priv;
BamfLegacyScreen *screen = bamf_legacy_screen_get_default ();
GList *l;
int i;
for (i = 0; i < priv->bad_prefixes->len; i++)
{
GRegex *regex = g_array_index (priv->bad_prefixes, GRegex *, i);
g_regex_unref (regex);
}
for (i = 0; i < priv->good_prefixes->len; i++)
{
GRegex *regex = g_array_index (priv->good_prefixes, GRegex *, i);
g_regex_unref (regex);
}
g_array_free (priv->bad_prefixes, TRUE);
g_array_free (priv->good_prefixes, TRUE);
g_hash_table_destroy (priv->desktop_id_table);
g_hash_table_destroy (priv->desktop_file_table);
g_hash_table_destroy (priv->desktop_class_table);
g_hash_table_destroy (priv->registered_pids);
g_list_free (priv->no_display_desktop);
if (priv->opened_closed_paths_table)
{
g_hash_table_destroy (priv->opened_closed_paths_table);
}
if (priv->dispatch_changes_id != 0)
{
g_source_remove (priv->dispatch_changes_id);
priv->dispatch_changes_id = 0;
}
g_list_free (priv->known_pids);
g_list_free_full (priv->views, g_object_unref);
g_signal_handlers_disconnect_by_data (screen, self);
for (l = priv->monitors; l; l = l->next)
g_signal_handlers_disconnect_by_data (G_OBJECT (l->data), self);
g_list_free_full (priv->monitors, g_object_unref);
g_list_free_full (priv->favorites, g_free);
priv->active_app = NULL;
priv->active_win = NULL;
static_matcher = NULL;
G_OBJECT_CLASS (bamf_matcher_parent_class)->finalize (object);
}
static void
bamf_matcher_class_init (BamfMatcherClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (BamfMatcherPrivate));
object_class->dispose = bamf_matcher_dispose;
object_class->finalize = bamf_matcher_finalize;
matcher_signals [FAVORITES_CHANGED] =
g_signal_new ("favorites-changed",
G_OBJECT_CLASS_TYPE (klass),
0, 0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
BamfMatcher *
bamf_matcher_get_default (void)
{
if (!BAMF_IS_MATCHER (static_matcher))
{
static_matcher = g_object_new (BAMF_TYPE_MATCHER, NULL);
}
return static_matcher;
}
./src/bamf-legacy-screen.h 0000644 0000156 0000165 00000007206 12704153435 015472 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#ifndef __BAMFLEGACY_SCREEN_H__
#define __BAMFLEGACY_SCREEN_H__
#include "bamf-view.h"
#include "bamf-legacy-window.h"
#include
#include
#define BAMF_TYPE_LEGACY_SCREEN (bamf_legacy_screen_get_type ())
#define BAMF_LEGACY_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_LEGACY_SCREEN, BamfLegacyScreen))
#define BAMF_IS_LEGACY_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_LEGACY_SCREEN))
#define BAMF_LEGACY_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_LEGACY_SCREEN, BamfLegacyScreenClass))
#define BAMF_IS_LEGACY_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_LEGACY_SCREEN))
#define BAMF_LEGACY_SCREEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_LEGACY_SCREEN, BamfLegacyScreenClass))
#define BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING "window-opening"
#define BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_CANCELED "window-opening-canceled"
#define BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_COMPLETED "window-opening-completed"
#define BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENED "window-opened"
#define BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_CLOSED "window-closed"
#define BAMF_LEGACY_SCREEN_SIGNAL_STACKING_CHANGED "stacking-changed"
#define BAMF_LEGACY_SCREEN_SIGNAL_ACTIVE_WINDOW_CHANGED "active-window-changed"
typedef struct _BamfLegacyScreen BamfLegacyScreen;
typedef struct _BamfLegacyScreenClass BamfLegacyScreenClass;
typedef struct _BamfLegacyScreenPrivate BamfLegacyScreenPrivate;
struct _BamfLegacyScreenClass
{
GObjectClass parent;
GList (*get_windows) (BamfLegacyScreen *legacy_screen);
/*< signals >*/
void (*window_opening) (BamfLegacyScreen *legacy_screen, const gchar *desktop_file);
void (*window_opening_completed) (BamfLegacyScreen *legacy_screen, const gchar *desktop_file);
void (*window_opening_canceled) (BamfLegacyScreen *legacy_screen, const gchar *desktop_file);
void (*window_opened) (BamfLegacyScreen *legacy_screen, BamfLegacyWindow *legacy_window);
void (*window_closed) (BamfLegacyScreen *legacy_screen, BamfLegacyWindow *legacy_window);
void (*stacking_changed) (BamfLegacyScreen *legacy_screen);
void (*active_window_changed) (BamfLegacyScreen *legacy_screen);
};
struct _BamfLegacyScreen
{
GObject parent;
/* private */
BamfLegacyScreenPrivate *priv;
};
GType bamf_legacy_screen_get_type (void) G_GNUC_CONST;
void bamf_legacy_screen_set_state_file (BamfLegacyScreen *screen, const char *file);
GList * bamf_legacy_screen_get_windows (BamfLegacyScreen *screen);
BamfLegacyWindow * bamf_legacy_screen_get_active_window (BamfLegacyScreen *screen);
BamfLegacyScreen * bamf_legacy_screen_get_default (void);
void bamf_legacy_screen_inject_window (BamfLegacyScreen *screen, guint xid);
#endif
./src/bamf-tab.h 0000644 0000156 0000165 00000004415 12704153435 013516 0 ustar jenkins jenkins /*
* 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: Robert Carr
*/
#ifndef __BAMFTAB_H__
#define __BAMFTAB_H__
#include "bamf-view.h"
#include
#include
#define BAMF_TYPE_TAB (bamf_tab_get_type ())
#define BAMF_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_TAB, BamfTab))
#define BAMF_IS_TAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_TAB))
#define BAMF_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_TAB, BamfTabClass))
#define BAMF_IS_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_TAB))
#define BAMF_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_TAB, BamfTabClass))
typedef struct _BamfTab BamfTab;
typedef struct _BamfTabClass BamfTabClass;
typedef struct _BamfTabPrivate BamfTabPrivate;
typedef void (*BamfTabPreviewReadyCallback) (BamfTab *, const gchar *, gpointer);
struct _BamfTabClass
{
BamfViewClass parent;
void (*raise) (BamfTab *self);
void (*close) (BamfTab *self);
void (*request_preview) (BamfTab *self, BamfTabPreviewReadyCallback callback, gpointer user_data);
};
struct _BamfTab
{
BamfView parent;
/* private */
BamfTabPrivate *priv;
};
GType bamf_tab_get_type (void) G_GNUC_CONST;
const gchar *bamf_tab_get_desktop_id (BamfTab *self);
const gchar *bamf_tab_get_location (BamfTab *self);
guint64 bamf_tab_get_xid (BamfTab *self);
gboolean bamf_tab_get_is_foreground_tab (BamfTab *self);
void bamf_tab_raise (BamfTab *self);
void bamf_tab_close (BamfTab *self);
void bamf_tab_request_preview (BamfTab *self, BamfTabPreviewReadyCallback callback, gpointer user_data);
#endif
./src/bamf-window.c 0000644 0000156 0000165 00000042534 12704153443 014255 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-legacy-screen.h"
#ifdef EXPORT_ACTIONS_MENU
#include
#include
#include
#include
#endif
#define BAMF_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_WINDOW, BamfWindowPrivate))
static void bamf_window_dbus_iface_init (BamfDBusItemWindowIface *iface);
G_DEFINE_TYPE_WITH_CODE (BamfWindow, bamf_window, BAMF_TYPE_VIEW,
G_IMPLEMENT_INTERFACE (BAMF_DBUS_ITEM_TYPE_WINDOW,
bamf_window_dbus_iface_init));
static GList *bamf_windows = NULL;
enum
{
PROP_0,
PROP_WINDOW,
};
struct _BamfWindowPrivate
{
BamfDBusItemWindow *dbus_iface;
BamfLegacyWindow *legacy_window;
BamfWindowMaximizationType maximized;
gint monitor;
#ifdef EXPORT_ACTIONS_MENU
DbusmenuServer *dbusmenu_server;
GtkWidget *action_menu;
gboolean was_active;
#endif
};
BamfLegacyWindow *
bamf_window_get_window (BamfWindow *self)
{
g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
if (BAMF_WINDOW_GET_CLASS (self)->get_window)
return BAMF_WINDOW_GET_CLASS (self)->get_window (self);
return self->priv->legacy_window;
}
BamfWindow *
bamf_window_get_transient (BamfWindow *self)
{
BamfLegacyWindow *legacy, *transient;
BamfWindow *other;
GList *l;
g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
legacy = bamf_window_get_window (self);
transient = bamf_legacy_window_get_transient (legacy);
if (transient)
{
for (l = bamf_windows; l; l = l->next)
{
other = l->data;
if (!BAMF_IS_WINDOW (other))
continue;
if (transient == bamf_window_get_window (other))
return other;
}
}
return NULL;
}
const char *
bamf_window_get_transient_path (BamfWindow *self)
{
BamfWindow *transient;
g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
transient = bamf_window_get_transient (self);
if (transient == NULL)
return "";
return bamf_view_get_path (BAMF_VIEW (transient));
}
guint32
bamf_window_get_window_type (BamfWindow *window)
{
g_return_val_if_fail (BAMF_IS_WINDOW (window), 0);
return (guint32) bamf_legacy_window_get_window_type (window->priv->legacy_window);
}
guint32
bamf_window_get_pid (BamfWindow *window)
{
g_return_val_if_fail (BAMF_IS_WINDOW (window), 0);
return bamf_legacy_window_get_pid (window->priv->legacy_window);
}
guint32
bamf_window_get_xid (BamfWindow *window)
{
g_return_val_if_fail (BAMF_IS_WINDOW (window), 0);
if (BAMF_WINDOW_GET_CLASS (window)->get_xid)
return BAMF_WINDOW_GET_CLASS (window)->get_xid (window);
return (guint32) bamf_legacy_window_get_xid (window->priv->legacy_window);
}
static void
handle_window_closed (BamfLegacyWindow * window, gpointer data)
{
BamfWindow *self;
self = (BamfWindow *) data;
g_return_if_fail (BAMF_IS_WINDOW (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
if (window == self->priv->legacy_window)
{
bamf_view_close (BAMF_VIEW (self));
}
}
static void
handle_name_changed (BamfLegacyWindow *window, BamfWindow *self)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
bamf_view_set_name (BAMF_VIEW (self), bamf_legacy_window_get_name (window));
}
static void
bamf_window_ensure_flags (BamfWindow *self)
{
g_return_if_fail (BAMF_IS_WINDOW (self));
#ifdef EXPORT_ACTIONS_MENU
self->priv->was_active = bamf_view_is_active (BAMF_VIEW (self));
#endif
bamf_view_set_active (BAMF_VIEW (self), bamf_legacy_window_is_active (self->priv->legacy_window));
bamf_view_set_urgent (BAMF_VIEW (self), bamf_legacy_window_needs_attention (self->priv->legacy_window));
bamf_view_set_user_visible (BAMF_VIEW (self), !bamf_legacy_window_is_skip_tasklist (self->priv->legacy_window));
BamfWindowMaximizationType maximized = bamf_window_maximized (self);
if (self->priv->maximized != maximized)
{
BamfWindowMaximizationType old_state = self->priv->maximized;
self->priv->maximized = maximized;
g_signal_emit_by_name (self, "maximized-changed", old_state, maximized);
}
#ifdef EXPORT_ACTIONS_MENU
if (self->priv->dbusmenu_server && !self->priv->was_active &&
!bamf_view_is_active (BAMF_VIEW (self)))
{
g_clear_object (&self->priv->dbusmenu_server);
g_clear_object (&self->priv->action_menu);
}
#endif
}
static void
bamf_window_ensure_monitor (BamfWindow *self)
{
g_return_if_fail (BAMF_IS_WINDOW (self));
gint monitor = bamf_window_get_monitor (self);
if (self->priv->monitor != monitor)
{
gint old_monitor = self->priv->monitor;
self->priv->monitor = monitor;
g_signal_emit_by_name (self, "monitor-changed", old_monitor, monitor);
}
}
static void
handle_state_changed (BamfLegacyWindow *window, BamfWindow *self)
{
bamf_window_ensure_flags (self);
}
static void
handle_geometry_changed (BamfLegacyWindow *window, BamfWindow *self)
{
bamf_window_ensure_monitor (self);
}
static const char *
bamf_window_get_view_type (BamfView *view)
{
return "window";
}
char *
bamf_window_get_string_hint (BamfWindow *self, const char* prop)
{
g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
return bamf_legacy_window_get_hint (self->priv->legacy_window, prop);
}
BamfWindowMaximizationType
bamf_window_maximized (BamfWindow *self)
{
g_return_val_if_fail (BAMF_IS_WINDOW (self), BAMF_WINDOW_FLOATING);
return bamf_legacy_window_maximized (self->priv->legacy_window);
}
gint
bamf_window_get_monitor (BamfWindow *self)
{
gint x, y, width, height;
g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
GdkScreen *gdk_screen = gdk_screen_get_default ();
bamf_legacy_window_get_geometry (self->priv->legacy_window, &x, &y, &width, &height);
return gdk_screen_get_monitor_at_point (gdk_screen, x + width/2, y + height/2);
}
static char *
bamf_window_get_stable_bus_name (BamfView *view)
{
BamfWindow *self;
g_return_val_if_fail (BAMF_IS_WINDOW (view), NULL);
self = BAMF_WINDOW (view);
return g_strdup_printf ("window/%u", bamf_legacy_window_get_xid (self->priv->legacy_window));
}
gint
bamf_window_get_stack_position (BamfWindow *self)
{
g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
return bamf_legacy_window_get_stacking_position (self->priv->legacy_window);
}
static void
active_window_changed (BamfLegacyScreen *screen, BamfWindow *window)
{
bamf_window_ensure_flags (window);
}
#ifdef EXPORT_ACTIONS_MENU
static gboolean
bamf_window_active_changed (BamfView *view, gboolean active)
{
BamfWindow *self = BAMF_WINDOW (view);
BamfWindowPrivate *priv = self->priv;
GtkWidget *window_menu;
BamfWindowType win_type;
const char *view_path;
if (!active && !priv->was_active)
{
g_clear_object (&priv->dbusmenu_server);
g_clear_object (&priv->action_menu);
return FALSE;
}
if (priv->dbusmenu_server)
return FALSE;
win_type = bamf_window_get_window_type (self);
if (win_type == BAMF_WINDOW_DOCK ||
win_type == BAMF_WINDOW_TOOLBAR ||
win_type == BAMF_WINDOW_MENU ||
win_type == BAMF_WINDOW_SPLASHSCREEN)
{
return FALSE;
}
window_menu = bamf_legacy_window_get_action_menu (priv->legacy_window);
if (!GTK_IS_WIDGET (window_menu))
return FALSE;
view_path = bamf_view_get_path (view);
priv->dbusmenu_server = dbusmenu_server_new (view_path);
priv->action_menu = gtk_menu_new ();
g_object_ref_sink (priv->action_menu);
GtkWidget *menuitem = gtk_menu_item_new_with_label (_("Window actions"));
gtk_widget_show (menuitem);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), window_menu);
gtk_menu_shell_append (GTK_MENU_SHELL (priv->action_menu), menuitem);
dbusmenu_server_set_root (priv->dbusmenu_server,
dbusmenu_gtk_parse_menu_structure (priv->action_menu));
return FALSE;
}
#endif
static gboolean
on_dbus_handle_get_pid (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
gint pid = bamf_window_get_pid (self);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", pid));
return TRUE;
}
static gboolean
on_dbus_handle_get_xid (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
guint32 xid = bamf_window_get_xid (self);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", xid));
return TRUE;
}
static gboolean
on_dbus_handle_transient (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
const char *transient_path = bamf_window_get_transient_path (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", transient_path));
return TRUE;
}
static gboolean
on_dbus_handle_window_type (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
BamfWindowType window_type = bamf_window_get_window_type (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u)", window_type));
return TRUE;
}
static gboolean
on_dbus_handle_xprop (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
const gchar *prop,
BamfWindow *self)
{
char *hint = bamf_window_get_string_hint (self, prop);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", hint ? hint : ""));
g_free (hint);
return TRUE;
}
static gboolean
on_dbus_handle_monitor (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
gint monitor = bamf_window_get_monitor (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(i)", monitor));
return TRUE;
}
static gboolean
on_dbus_handle_maximized (BamfDBusItemWindow *interface,
GDBusMethodInvocation *invocation,
BamfWindow *self)
{
BamfWindowMaximizationType maximized = bamf_window_maximized (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(i)", maximized));
return TRUE;
}
static void
bamf_window_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
BamfWindow *self;
self = BAMF_WINDOW (object);
switch (property_id)
{
case PROP_WINDOW:
self->priv->legacy_window = BAMF_LEGACY_WINDOW (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
bamf_window_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
BamfWindow *self;
self = BAMF_WINDOW (object);
switch (property_id)
{
case PROP_WINDOW:
g_value_set_object (value, self->priv->legacy_window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
on_maximized_changed (BamfWindow *self, BamfWindowMaximizationType old,
BamfWindowMaximizationType new, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_WINDOW (self));
g_signal_emit_by_name (self->priv->dbus_iface, "maximized-changed", old, new);
}
static void
on_monitor_changed (BamfWindow *self, gint old, gint new, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_WINDOW (self));
g_signal_emit_by_name (self->priv->dbus_iface, "monitor-changed", old, new);
}
static void
bamf_window_constructed (GObject *object)
{
BamfWindow *self;
BamfLegacyWindow *window;
if (G_OBJECT_CLASS (bamf_window_parent_class)->constructed)
G_OBJECT_CLASS (bamf_window_parent_class)->constructed (object);
g_object_get (object, "legacy-window", &window, NULL);
self = BAMF_WINDOW (object);
bamf_windows = g_list_prepend (bamf_windows, self);
bamf_view_set_name (BAMF_VIEW (self), bamf_legacy_window_get_name (window));
g_signal_connect (G_OBJECT (window), "name-changed",
(GCallback) handle_name_changed, self);
g_signal_connect (G_OBJECT (window), "state-changed",
(GCallback) handle_state_changed, self);
g_signal_connect (G_OBJECT (window), "geometry-changed",
(GCallback) handle_geometry_changed, self);
g_signal_connect (G_OBJECT (window), "closed",
(GCallback) handle_window_closed, self);
self->priv->maximized = -1;
self->priv->monitor = -1;
bamf_window_ensure_flags (self);
bamf_window_ensure_monitor (self);
}
static void
bamf_window_dispose (GObject *object)
{
BamfWindow *self;
self = BAMF_WINDOW (object);
bamf_windows = g_list_remove (bamf_windows, self);
g_signal_handlers_disconnect_by_func (bamf_legacy_screen_get_default (),
active_window_changed, self);
if (self->priv->legacy_window)
{
g_signal_handlers_disconnect_by_data (self->priv->legacy_window, self);
g_object_unref (self->priv->legacy_window);
self->priv->legacy_window = NULL;
}
#ifdef EXPORT_ACTIONS_MENU
g_clear_object (&self->priv->dbusmenu_server);
g_clear_object (&self->priv->action_menu);
#endif
G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);
}
static void
bamf_window_finalize (GObject *object)
{
BamfWindow *self;
self = BAMF_WINDOW (object);
g_object_unref (self->priv->dbus_iface);
G_OBJECT_CLASS (bamf_window_parent_class)->finalize (object);
}
static void
bamf_window_init (BamfWindow * self)
{
self->priv = BAMF_WINDOW_GET_PRIVATE (self);
/* Initializing the dbus interface */
self->priv->dbus_iface = _bamf_dbus_item_window_skeleton_new ();
/* We need to connect to the object own signals to redirect them to the dbus
* interface */
g_signal_connect (self, "maximized-changed", G_CALLBACK (on_maximized_changed), NULL);
g_signal_connect (self, "monitor-changed", G_CALLBACK (on_monitor_changed), NULL);
/* Registering signal callbacks to reply to dbus method calls */
g_signal_connect (self->priv->dbus_iface, "handle-get-pid",
G_CALLBACK (on_dbus_handle_get_pid), self);
g_signal_connect (self->priv->dbus_iface, "handle-get-xid",
G_CALLBACK (on_dbus_handle_get_xid), self);
g_signal_connect (self->priv->dbus_iface, "handle-transient",
G_CALLBACK (on_dbus_handle_transient), self);
g_signal_connect (self->priv->dbus_iface, "handle-window-type",
G_CALLBACK (on_dbus_handle_window_type), self);
g_signal_connect (self->priv->dbus_iface, "handle-xprop",
G_CALLBACK (on_dbus_handle_xprop), self);
g_signal_connect (self->priv->dbus_iface, "handle-monitor",
G_CALLBACK (on_dbus_handle_monitor), self);
g_signal_connect (self->priv->dbus_iface, "handle-maximized",
G_CALLBACK (on_dbus_handle_maximized), self);
/* Setting the interface for the dbus object */
_bamf_dbus_item_object_skeleton_set_window (BAMF_DBUS_ITEM_OBJECT_SKELETON (self),
self->priv->dbus_iface);
g_signal_connect (G_OBJECT (bamf_legacy_screen_get_default ()), "active-window-changed",
(GCallback) active_window_changed, self);
}
static void
bamf_window_dbus_iface_init (BamfDBusItemWindowIface *iface)
{
}
static void
bamf_window_class_init (BamfWindowClass * klass)
{
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
object_class->dispose = bamf_window_dispose;
object_class->finalize = bamf_window_finalize;
object_class->get_property = bamf_window_get_property;
object_class->set_property = bamf_window_set_property;
object_class->constructed = bamf_window_constructed;
view_class->view_type = bamf_window_get_view_type;
view_class->stable_bus_name = bamf_window_get_stable_bus_name;
#ifdef EXPORT_ACTIONS_MENU
view_class->active_changed = bamf_window_active_changed;
#endif
pspec = g_param_spec_object ("legacy-window", "legacy-window", "legacy-window",
BAMF_TYPE_LEGACY_WINDOW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property (object_class, PROP_WINDOW, pspec);
g_type_class_add_private (klass, sizeof (BamfWindowPrivate));
}
BamfWindow *
bamf_window_new (BamfLegacyWindow *window)
{
BamfWindow *self;
self = (BamfWindow *) g_object_new (BAMF_TYPE_WINDOW, "legacy-window", window, NULL);
return self;
}
./src/bamf-legacy-window-test.c 0000644 0000156 0000165 00000037103 12704153443 016470 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#include "bamf-legacy-window-test.h"
#include "bamf-legacy-screen-private.h"
G_DEFINE_TYPE (BamfLegacyWindowTest, bamf_legacy_window_test, BAMF_TYPE_LEGACY_WINDOW);
guint
bamf_legacy_window_test_get_pid (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->pid;
}
guint32
bamf_legacy_window_test_get_xid (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->xid;
}
void
bamf_legacy_window_test_set_attention (BamfLegacyWindowTest *self, gboolean val)
{
if (self->needs_attention == val)
return;
self->needs_attention = val;
g_signal_emit_by_name (self, "state-changed");
}
gboolean
bamf_legacy_window_test_needs_attention (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->needs_attention;
}
void
bamf_legacy_window_test_set_active (BamfLegacyWindowTest *self, gboolean val)
{
if (self->is_active == val)
return;
self->is_active = val;
g_signal_emit_by_name (self, "state-changed");
}
gboolean
bamf_legacy_window_test_is_active (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->is_active;
}
void
bamf_legacy_window_test_set_desktop (BamfLegacyWindowTest *self, gboolean val)
{
if (self->is_desktop == val)
return;
self->is_desktop = val;
g_signal_emit_by_name (self, "state-changed");
}
gboolean
bamf_legacy_window_test_is_desktop (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->is_desktop;
}
void
bamf_legacy_window_test_set_skip (BamfLegacyWindowTest *self, gboolean val)
{
if (self->is_skip == val)
return;
self->is_skip = val;
g_signal_emit_by_name (self, "state-changed");
}
gboolean
bamf_legacy_window_test_is_skip_tasklist (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->is_skip;
}
void
bamf_legacy_window_test_set_name (BamfLegacyWindowTest *self, const char *val)
{
if (g_strcmp0 (self->name, val) == 0)
return;
g_free (self->name);
self->name = g_strdup (val);
g_signal_emit_by_name (self, "name-changed");
}
void
bamf_legacy_window_test_set_icon (BamfLegacyWindowTest *self, const char *val)
{
if (g_strcmp0 (self->icon, val) == 0)
return;
g_free (self->icon);
self->icon = g_strdup (val);
}
void
bamf_legacy_window_test_set_role (BamfLegacyWindowTest *self, const char *val)
{
if (g_strcmp0 (self->role, val) == 0)
return;
g_free (self->role);
self->role = g_strdup (val);
g_signal_emit_by_name (self, "role-changed");
}
void
bamf_legacy_window_test_set_wmclass (BamfLegacyWindowTest *self, const char *class_name, const char *instance_name)
{
gboolean changed = FALSE;
if (g_strcmp0 (self->wm_class_name, class_name) != 0)
{
g_free (self->wm_class_name);
self->wm_class_name = g_strdup (class_name);
changed = TRUE;
}
if (g_strcmp0 (self->wm_class_instance, instance_name) != 0)
{
g_free (self->wm_class_instance);
self->wm_class_instance = g_strdup (instance_name);
changed = TRUE;
}
if (changed)
g_signal_emit_by_name (self, "class-changed");
}
static const char *
bamf_legacy_window_test_get_name (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->name;
}
static const char *
bamf_legacy_window_test_get_role (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->role;
}
static BamfLegacyWindow *
bamf_legacy_window_test_get_transient (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->transient_window;
}
static const char *
bamf_legacy_window_test_get_class_name (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->wm_class_name;
}
static const char *
bamf_legacy_window_test_get_class_instance_name (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->wm_class_instance;
}
const char *
bamf_legacy_window_test_get_exec_string (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->exec;
}
const char *
bamf_legacy_window_test_get_working_dir (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->working_dir;
}
char *
bamf_legacy_window_test_get_process_name (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return g_strdup (self->process_name);
}
char *
bamf_legacy_window_test_get_app_id (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (legacy_window), NULL);
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return g_strdup (self->application_id);
}
char *
bamf_legacy_window_test_get_unique_bus_name (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (legacy_window), NULL);
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return g_strdup (self->unique_bus_name);
}
char *
bamf_legacy_window_test_get_menu_object_path (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (legacy_window), NULL);
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return g_strdup (self->dbus_menu_object_path);
}
void
bamf_legacy_window_test_get_geometry (BamfLegacyWindow *legacy_window,
gint *x, gint *y,
gint *width, gint *height)
{
BamfLegacyWindowTest *self;
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (legacy_window));
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
*x = self->geometry.x;
*y = self->geometry.y;
*width = self->geometry.width;
*height = self->geometry.height;
}
BamfWindowMaximizationType
bamf_legacy_window_test_maximized (BamfLegacyWindow *legacy_window)
{
BamfLegacyWindowTest *self;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (legacy_window), BAMF_WINDOW_FLOATING);
self = BAMF_LEGACY_WINDOW_TEST (legacy_window);
return self->maximized;
}
void
bamf_legacy_window_test_close (BamfLegacyWindowTest *self)
{
self->is_closed = TRUE;
g_signal_emit_by_name (self, "closed");
}
void
bamf_legacy_window_test_set_geometry (BamfLegacyWindowTest *self, int x, int y,
int width, int height)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (self));
self->geometry.x = x;
self->geometry.y = y;
self->geometry.width = width;
self->geometry.height = height;
g_signal_emit_by_name (self, BAMF_LEGACY_WINDOW_SIGNAL_GEOMETRY_CHANGED);
}
void
bamf_legacy_window_test_set_maximized (BamfLegacyWindowTest *self,
BamfWindowMaximizationType maximized)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (self));
self->maximized = maximized;
g_signal_emit_by_name (self, BAMF_LEGACY_WINDOW_SIGNAL_GEOMETRY_CHANGED);
g_signal_emit_by_name (self, BAMF_LEGACY_WINDOW_SIGNAL_STATE_CHANGED);
}
void
bamf_legacy_window_test_set_application_id (BamfLegacyWindowTest *self, const char *id)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (self));
self->application_id = g_strdup (id);
}
void
bamf_legacy_window_test_set_unique_bus_name (BamfLegacyWindowTest *self, const char *bus_name)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (self));
self->unique_bus_name = g_strdup (bus_name);
}
void
bamf_legacy_window_test_set_dbus_menu_object_path (BamfLegacyWindowTest *self, const char *object_path)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (self));
self->dbus_menu_object_path = g_strdup (object_path);
}
gboolean
bamf_legacy_window_test_is_closed (BamfLegacyWindow *window)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (window), TRUE);
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (window);
return self->is_closed;
}
static void
handle_destroy_notify (BamfLegacyWindowTest *copy, BamfLegacyWindowTest *self_was_here)
{
BamfLegacyScreen *screen = bamf_legacy_screen_get_default ();
_bamf_legacy_screen_open_test_window (screen, copy);
}
void
bamf_legacy_window_test_reopen (BamfLegacyWindow *window)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (window));
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (window);
BamfLegacyWindowTest *copy = bamf_legacy_window_copy (self);
g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify, copy);
bamf_legacy_window_test_close (self);
}
BamfWindowType
bamf_legacy_window_test_get_window_type (BamfLegacyWindow *window)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (window), TRUE);
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (window);
return self->window_type;
}
char *
bamf_legacy_window_test_get_hint (BamfLegacyWindow *window, const char *name)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (window), NULL);
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (window);
return g_strdup (g_hash_table_lookup (self->hints, name));
}
void
bamf_legacy_window_test_set_hint (BamfLegacyWindow *window, const char *name, const char *value)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (window));
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (window);
g_hash_table_insert (self->hints, g_strdup (name), g_strdup (value));
}
static char *
bamf_legacy_window_test_save_mini_icon (BamfLegacyWindow *window)
{
return g_strdup (BAMF_LEGACY_WINDOW_TEST (window)->icon);
}
GtkWidget *
bamf_legacy_window_test_get_action_menu (BamfLegacyWindow *window)
{
return NULL;
}
void
bamf_legacy_window_test_show_action_menu (BamfLegacyWindow *window, guint32 time, guint button, gint x, gint y)
{}
static void
bamf_legacy_window_test_finalize (GObject *object)
{
BamfLegacyWindowTest *self = BAMF_LEGACY_WINDOW_TEST (object);
g_free (self->name);
g_free (self->icon);
g_free (self->role);
g_free (self->wm_class_name);
g_free (self->wm_class_instance);
g_free (self->exec);
g_free (self->working_dir);
g_free (self->process_name);
g_free (self->application_id);
g_free (self->unique_bus_name);
g_free (self->dbus_menu_object_path);
g_hash_table_unref (self->hints);
G_OBJECT_CLASS (bamf_legacy_window_test_parent_class)->finalize (object);
}
void
bamf_legacy_window_test_class_init (BamfLegacyWindowTestClass *klass)
{
BamfLegacyWindowClass *win_class = BAMF_LEGACY_WINDOW_CLASS (klass);
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
obj_class->finalize = bamf_legacy_window_test_finalize;
win_class->get_transient = bamf_legacy_window_test_get_transient;
win_class->get_name = bamf_legacy_window_test_get_name;
win_class->save_mini_icon = bamf_legacy_window_test_save_mini_icon;
win_class->get_role = bamf_legacy_window_test_get_role;
win_class->get_class_name = bamf_legacy_window_test_get_class_name;
win_class->get_class_instance_name = bamf_legacy_window_test_get_class_instance_name;
win_class->get_exec_string = bamf_legacy_window_test_get_exec_string;
win_class->get_working_dir = bamf_legacy_window_test_get_working_dir;
win_class->get_process_name = bamf_legacy_window_test_get_process_name;
win_class->get_xid = bamf_legacy_window_test_get_xid;
win_class->get_pid = bamf_legacy_window_test_get_pid;
win_class->needs_attention = bamf_legacy_window_test_needs_attention;
win_class->is_skip_tasklist = bamf_legacy_window_test_is_skip_tasklist;
win_class->is_desktop = bamf_legacy_window_test_is_desktop;
win_class->is_active = bamf_legacy_window_test_is_active;
win_class->get_app_id = bamf_legacy_window_test_get_app_id;
win_class->get_unique_bus_name = bamf_legacy_window_test_get_unique_bus_name;
win_class->get_menu_object_path = bamf_legacy_window_test_get_menu_object_path;
win_class->get_geometry = bamf_legacy_window_test_get_geometry;
win_class->get_window_type = bamf_legacy_window_test_get_window_type;
win_class->maximized = bamf_legacy_window_test_maximized;
win_class->is_closed = bamf_legacy_window_test_is_closed;
win_class->get_hint = bamf_legacy_window_test_get_hint;
win_class->set_hint = bamf_legacy_window_test_set_hint;
win_class->get_action_menu = bamf_legacy_window_test_get_action_menu;
win_class->show_action_menu = bamf_legacy_window_test_show_action_menu;
win_class->reopen = bamf_legacy_window_test_reopen;
}
void
bamf_legacy_window_test_init (BamfLegacyWindowTest *self)
{
self->pid = g_random_int_range (1, 100000);
self->maximized = BAMF_WINDOW_FLOATING;
self->is_closed = FALSE;
self->hints = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
BamfLegacyWindowTest *
bamf_legacy_window_copy (BamfLegacyWindowTest *self)
{
BamfLegacyWindowTest *copy;
copy = g_object_new (BAMF_TYPE_LEGACY_WINDOW_TEST, NULL);
copy->xid = self->xid;
copy->pid = self->pid;
copy->name = g_strdup (self->name);
copy->icon = g_strdup (self->icon);
copy->role = g_strdup (self->role);
copy->wm_class_name = g_strdup (self->wm_class_name);
copy->wm_class_instance = g_strdup (self->wm_class_instance);
copy->exec = g_strdup (self->exec);
copy->working_dir = g_strdup (self->working_dir);
copy->process_name = g_strdup (self->process_name);
copy->application_id = g_strdup (self->application_id);
copy->unique_bus_name = g_strdup (self->unique_bus_name);
copy->dbus_menu_object_path = g_strdup (self->dbus_menu_object_path);
copy->transient_window = self->transient_window;
copy->needs_attention = self->needs_attention;
copy->is_desktop = self->is_desktop;
copy->is_skip = self->is_skip;
copy->is_active = self->is_active;
copy->is_closed = self->is_closed;
copy->geometry = self->geometry;
copy->maximized = self->maximized;
copy->window_type = self->window_type;
copy->hints = g_hash_table_ref (self->hints);
return copy;
}
BamfLegacyWindowTest *
bamf_legacy_window_test_new (guint32 xid, const gchar *name, const gchar *wmclass_name, const gchar *exec)
{
BamfLegacyWindowTest *self;
self = g_object_new (BAMF_TYPE_LEGACY_WINDOW_TEST, NULL);
self->window_type = BAMF_WINDOW_NORMAL;
self->xid = xid;
self->name = g_strdup (name);
self->wm_class_name = g_strdup (wmclass_name);
self->exec = g_strdup (exec);
self->working_dir = g_get_current_dir ();
if (self->exec)
{
gchar **splitted_exec = g_strsplit (exec, " ", 2);
gchar *tmp = g_utf8_strrchr (splitted_exec[0], -1, G_DIR_SEPARATOR);
self->process_name = g_strdup (tmp ? tmp + 1 : splitted_exec[0]);
g_strfreev (splitted_exec);
}
return self;
}
./src/bamf-matcher.h 0000644 0000156 0000165 00000012411 12704153435 014366 0 ustar jenkins jenkins /*
* 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: Jason Smith
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMFMATCHER_H__
#define __BAMFMATCHER_H__
#include "bamf-view.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BAMF_TYPE_MATCHER (bamf_matcher_get_type ())
#define BAMF_MATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_MATCHER, BamfMatcher))
#define BAMF_IS_MATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_MATCHER))
#define BAMF_MATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_MATCHER, BamfMatcherClass))
#define BAMF_IS_MATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_MATCHER))
#define BAMF_MATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_MATCHER, BamfMatcherClass))
#define _BAMF_DESKTOP_FILE "_BAMF_DESKTOP_FILE"
#define _GTK_APPLICATION_ID "_GTK_APPLICATION_ID"
typedef struct _BamfMatcher BamfMatcher;
typedef struct _BamfMatcherClass BamfMatcherClass;
typedef struct _BamfMatcherPrivate BamfMatcherPrivate;
struct _BamfMatcherClass
{
BamfDBusMatcherSkeletonClass parent;
};
struct _BamfMatcher
{
BamfDBusMatcherSkeleton parent;
/* private */
BamfMatcherPrivate *priv;
};
GType bamf_matcher_get_type (void) G_GNUC_CONST;
void bamf_matcher_load_desktop_file (BamfMatcher * self,
const char * desktop_file);
void bamf_matcher_register_desktop_file_for_pid (BamfMatcher * self,
const char *application,
guint64 pid);
void bamf_matcher_set_starting_desktop_file (BamfMatcher * self,
const char *desktop_file,
gboolean starting);
const char * bamf_matcher_get_desktop_file_class (BamfMatcher * self,
const char * desktop_file);
const char * bamf_matcher_get_active_application (BamfMatcher *matcher);
const char * bamf_matcher_get_active_window (BamfMatcher *matcher);
const char * bamf_matcher_application_for_xid (BamfMatcher *matcher,
guint32 xid);
gboolean bamf_matcher_application_is_running (BamfMatcher *matcher,
const char *application);
GVariant * bamf_matcher_application_dbus_paths (BamfMatcher *matcher);
GVariant * bamf_matcher_window_dbus_paths (BamfMatcher *matcher);
const char * bamf_matcher_dbus_path_for_application (BamfMatcher *matcher,
const char *application);
void bamf_matcher_register_favorites (BamfMatcher *matcher,
const char **favorites);
GList * bamf_matcher_get_favorites (BamfMatcher *matcher);
GVariant * bamf_matcher_running_application_paths (BamfMatcher *matcher);
GVariant * bamf_matcher_tab_dbus_paths (BamfMatcher *matcher);
GVariant * bamf_matcher_xids_for_application (BamfMatcher *matcher,
const char *application);
GVariant * bamf_matcher_get_window_stack_for_monitor (BamfMatcher *matcher,
gint monitor);
gboolean bamf_matcher_is_valid_process_prefix (BamfMatcher *matcher,
const char *process_name);
gboolean bamf_matcher_is_valid_class_name (BamfMatcher *matcher,
const char *class_name);
char * bamf_matcher_get_trimmed_exec (BamfMatcher *matcher,
const char *exec_string);
BamfView * bamf_matcher_get_view_by_path (BamfMatcher *matcher,
const char *view_path);
BamfMatcher * bamf_matcher_get_default (void);
#endif
./src/main.c 0000644 0000156 0000165 00000003653 12704153435 012767 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "config.h"
#include "bamf-daemon.h"
#include "bamf-legacy-screen.h"
#include "main.h"
int
main (int argc, char **argv)
{
BamfDaemon *daemon;
GOptionContext *options;
GError *error = NULL;
char *state_file = NULL;
gtk_init (&argc, &argv);
glibtop_init ();
options = g_option_context_new ("");
g_option_context_set_help_enabled (options, TRUE);
g_option_context_set_summary (options, "It's one, and so are we...");
GOptionEntry entries[] =
{
{"load-file", 'l', 0, G_OPTION_ARG_STRING, &state_file, "Load bamf state from file instead of the system", NULL },
{NULL}
};
g_option_context_add_main_entries (options, entries, NULL);
g_option_context_add_group (options, gtk_get_option_group (FALSE));
g_option_context_parse (options, &argc, &argv, &error);
if (error)
{
g_print ("%s, error: %s\n", g_option_context_get_help (options, TRUE, NULL), error->message);
g_clear_error (&error);
exit (1);
}
if (state_file)
{
bamf_legacy_screen_set_state_file (bamf_legacy_screen_get_default (), state_file);
}
daemon = bamf_daemon_get_default ();
bamf_daemon_start (daemon);
g_object_unref (daemon);
return 0;
}
./src/bamf-legacy-window.c 0000644 0000156 0000165 00000054507 12704153443 015522 0 ustar jenkins jenkins /*
* 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: Jason Smith
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "config.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-screen.h"
#include "bamf-xutils.h"
#include
#include
#include
#include
#include
G_DEFINE_TYPE (BamfLegacyWindow, bamf_legacy_window, G_TYPE_OBJECT);
#define BAMF_LEGACY_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_LEGACY_WINDOW, BamfLegacyWindowPrivate))
#define WNCK_WINDOW_BAMF_DATA "bamf-legacy-window"
enum
{
NAME_CHANGED,
ROLE_CHANGED,
CLASS_CHANGED,
STATE_CHANGED,
GEOMETRY_CHANGED,
CLOSED,
LAST_SIGNAL,
};
static guint legacy_window_signals[LAST_SIGNAL] = { 0 };
struct _BamfLegacyWindowPrivate
{
WnckWindow * legacy_window;
GtkWidget * action_menu;
GFile * mini_icon;
gchar * exec_string;
gchar * working_dir;
gboolean is_closed;
};
gboolean
bamf_legacy_window_is_active (BamfLegacyWindow *self)
{
WnckWindow *active;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), FALSE);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_active)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_active (self);
active = wnck_screen_get_active_window (wnck_screen_get_default ());
return active == self->priv->legacy_window;
}
BamfWindowType
bamf_legacy_window_get_window_type (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), 0);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_window_type)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_window_type (self);
g_return_val_if_fail (self->priv->legacy_window, 0);
return (BamfWindowType) wnck_window_get_window_type (self->priv->legacy_window);
}
gboolean
bamf_legacy_window_needs_attention (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), FALSE);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->needs_attention)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->needs_attention (self);
if (!self->priv->legacy_window)
return FALSE;
return wnck_window_needs_attention (self->priv->legacy_window);
}
gboolean
bamf_legacy_window_is_skip_tasklist (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), FALSE);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_skip_tasklist)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_skip_tasklist (self);
if (!self->priv->legacy_window)
return FALSE;
return wnck_window_is_skip_tasklist (self->priv->legacy_window);
}
const char *
bamf_legacy_window_get_class_instance_name (BamfLegacyWindow *self)
{
WnckWindow *window;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
window = self->priv->legacy_window;
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_class_instance_name)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_class_instance_name (self);
if (!window)
return NULL;
return wnck_window_get_class_instance_name (window);
}
const char *
bamf_legacy_window_get_class_name (BamfLegacyWindow *self)
{
WnckWindow *window;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
window = self->priv->legacy_window;
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_class_name)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_class_name (self);
if (!window)
return NULL;
return wnck_window_get_class_group_name (window);
}
const char *
bamf_legacy_window_get_name (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_name)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_name (self);
if (!self->priv->legacy_window)
return NULL;
return wnck_window_get_name (self->priv->legacy_window);
}
const char *
bamf_legacy_window_get_role (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_role)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_role (self);
if (!self->priv->legacy_window)
return NULL;
return wnck_window_get_role (self->priv->legacy_window);
}
char *
bamf_legacy_window_get_process_name (BamfLegacyWindow *self)
{
gchar *stat_path;
gchar *contents;
gchar **lines;
gchar **sections;
gchar *result = NULL;
guint pid;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_process_name)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_process_name (self);
pid = bamf_legacy_window_get_pid (self);
if (pid <= 0)
return NULL;
stat_path = g_strdup_printf ("/proc/%i/status", pid);
if (g_file_get_contents (stat_path, &contents, NULL, NULL))
{
lines = g_strsplit (contents, "\n", 2);
if (lines && g_strv_length (lines) > 0)
{
sections = g_strsplit (lines[0], "\t", 0);
if (sections)
{
if (g_strv_length (sections) > 1)
result = g_strdup (sections[1]);
g_strfreev (sections);
}
g_strfreev (lines);
}
g_free (contents);
}
g_free (stat_path);
return result;
}
const char *
bamf_legacy_window_get_exec_string (BamfLegacyWindow *self)
{
guint pid;
gchar **argv;
glibtop_proc_args buffer;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_exec_string)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_exec_string (self);
if (self->priv->exec_string)
return self->priv->exec_string;
pid = bamf_legacy_window_get_pid (self);
if (pid == 0)
return NULL;
argv = glibtop_get_proc_argv (&buffer, pid, 0);
self->priv->exec_string = g_strstrip (g_strjoinv (" ", argv));
g_strfreev (argv);
return self->priv->exec_string;
}
const char *
bamf_legacy_window_get_working_dir (BamfLegacyWindow *self)
{
guint pid = 0;
gchar **dirs;
glibtop_proc_wd buffer_wd;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_working_dir)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_working_dir (self);
if (self->priv->working_dir)
return self->priv->working_dir;
pid = bamf_legacy_window_get_pid (self);
if (pid == 0)
return NULL;
dirs = glibtop_get_proc_wd (&buffer_wd, pid);
if (!dirs)
return NULL;
self->priv->working_dir = g_strdup (dirs[0] ? g_strstrip (dirs[0]) : NULL);
g_strfreev (dirs);
return self->priv->working_dir;
}
char *
bamf_legacy_window_save_mini_icon (BamfLegacyWindow *self)
{
WnckWindow *window;
GdkPixbuf *pbuf;
GFile *tmp;
GFileIOStream *iostream;
GOutputStream *output;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->save_mini_icon)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->save_mini_icon (self);
if (self->priv->mini_icon)
{
if (g_file_query_exists (self->priv->mini_icon, NULL))
{
return g_file_get_path (self->priv->mini_icon);
}
else
{
g_object_unref (self->priv->mini_icon);
self->priv->mini_icon = NULL;
}
}
window = self->priv->legacy_window;
if (!window)
return NULL;
if (wnck_window_get_icon_is_fallback (window))
return NULL;
tmp = g_file_new_tmp (".bamficonXXXXXX", &iostream, NULL);
if (!tmp)
return NULL;
output = g_io_stream_get_output_stream (G_IO_STREAM (iostream));
pbuf = wnck_window_get_icon (window);
if (gdk_pixbuf_save_to_stream (pbuf, output, "png", NULL, NULL, NULL))
{
self->priv->mini_icon = g_object_ref (tmp);
}
g_object_unref (iostream);
g_object_unref (tmp);
return g_file_get_path (self->priv->mini_icon);
}
GFile *
bamf_legacy_window_get_saved_mini_icon (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
return self->priv->mini_icon;
}
guint
bamf_legacy_window_get_pid (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), 0);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_pid)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_pid (self);
if (!self->priv->legacy_window)
return 0;
int pid = wnck_window_get_pid (self->priv->legacy_window);
return G_LIKELY (pid >= 0) ? pid : 0;
}
guint32
bamf_legacy_window_get_xid (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), 0);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_xid)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_xid (self);
if (!self->priv->legacy_window)
return 0;
return (guint32) wnck_window_get_xid (self->priv->legacy_window);
}
BamfLegacyWindow *
bamf_legacy_window_get_transient (BamfLegacyWindow *self)
{
BamfLegacyScreen *screen;
BamfLegacyWindow *other;
GList *windows, *l;
WnckWindow *transient_legacy;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_transient)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_transient (self);
g_return_val_if_fail (self->priv->legacy_window, NULL);
transient_legacy = wnck_window_get_transient (self->priv->legacy_window);
screen = bamf_legacy_screen_get_default ();
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
windows = bamf_legacy_screen_get_windows (screen);
for (l = windows; l; l = l->next)
{
other = l->data;
if (!BAMF_IS_LEGACY_WINDOW (other))
continue;
if (other->priv->legacy_window == transient_legacy)
return other;
}
return NULL;
}
gint
bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self)
{
BamfLegacyScreen *screen;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), -1);
screen = bamf_legacy_screen_get_default ();
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), -1);
return g_list_index (bamf_legacy_screen_get_windows (screen), self);
}
static void
handle_window_signal (WnckWindow *window, gpointer data)
{
BamfLegacyWindow *self = g_object_get_data (G_OBJECT (window), WNCK_WINDOW_BAMF_DATA);
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
g_signal_emit (self, legacy_window_signals[GPOINTER_TO_UINT (data)], 0);
}
static void
handle_state_changed (WnckWindow *window,
WnckWindowState change_mask,
WnckWindowState new_state,
BamfLegacyWindow *self)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
g_signal_emit (self, legacy_window_signals[STATE_CHANGED], 0);
}
gboolean
bamf_legacy_window_is_closed (BamfLegacyWindow *self)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), TRUE);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_closed)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->is_closed (self);
return self->priv->is_closed;
}
void
bamf_legacy_window_get_geometry (BamfLegacyWindow *self, gint *x, gint *y,
gint *width, gint *height)
{
if (x) *x = 0;
if (y) *y = 0;
if (width) *width = 0;
if (height) *height = 0;
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_app_id)
BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_app_id (self);
if (!self->priv->legacy_window)
return;
wnck_window_get_geometry (self->priv->legacy_window, x, y, width, height);
}
BamfWindowMaximizationType
bamf_legacy_window_maximized (BamfLegacyWindow *self)
{
WnckWindowState window_state;
BamfWindowMaximizationType maximization_type;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), BAMF_WINDOW_FLOATING);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->maximized)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->maximized (self);
if (!self->priv->legacy_window)
return BAMF_WINDOW_FLOATING;
window_state = wnck_window_get_state (self->priv->legacy_window);
gboolean vertical = (window_state & WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY);
gboolean horizontal = (window_state & WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY);
if (vertical && horizontal)
{
maximization_type = BAMF_WINDOW_MAXIMIZED;
}
else if (horizontal)
{
maximization_type = BAMF_WINDOW_HORIZONTAL_MAXIMIZED;
}
else if (vertical)
{
maximization_type = BAMF_WINDOW_VERTICAL_MAXIMIZED;
}
else
{
maximization_type = BAMF_WINDOW_FLOATING;
}
return maximization_type;
}
char *
bamf_legacy_window_get_hint (BamfLegacyWindow *self, const char *name)
{
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
g_return_val_if_fail (name, NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_hint)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_hint (self, name);
g_return_val_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window), NULL);
guint xid = bamf_legacy_window_get_xid (self);
return bamf_xutils_get_string_window_hint (xid, name);
}
void
bamf_legacy_window_set_hint (BamfLegacyWindow *self, const char *name, const char *value)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
g_return_if_fail (name);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->set_hint)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->set_hint (self, name, value);
g_return_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window));
guint xid = bamf_legacy_window_get_xid (self);
bamf_xutils_set_string_window_hint (xid, name, value);
}
static void
top_window_action_menu (GtkMenu *menu, gint *x, gint *y, gboolean *push, gpointer data)
{
BamfLegacyWindow *self = data;
gint w, h;
wnck_window_get_client_window_geometry (self->priv->legacy_window, x, y, &w, &h);
*push = TRUE;
}
GtkWidget *
bamf_legacy_window_get_action_menu (BamfLegacyWindow *self)
{
BamfLegacyWindowPrivate *priv;
g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (self), NULL);
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_action_menu)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->get_action_menu (self);
priv = self->priv;
g_return_val_if_fail (WNCK_IS_WINDOW (priv->legacy_window), NULL);
if (!priv->action_menu)
{
priv->action_menu = wnck_action_menu_new (priv->legacy_window);
g_object_add_weak_pointer (G_OBJECT (priv->action_menu),
(gpointer *) &priv->action_menu);
}
return priv->action_menu;
}
void bamf_legacy_window_show_action_menu (BamfLegacyWindow *self, guint32 time,
guint button, gint x, gint y)
{
BamfLegacyWindowPrivate *priv;
GtkWidget *menu;
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->show_action_menu)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->show_action_menu (self, button, time, x, y);
g_return_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window));
priv = self->priv;
if (priv->action_menu && gtk_widget_is_visible (GTK_WIDGET (priv->action_menu)))
return;
menu = bamf_legacy_window_get_action_menu (self);
g_object_ref_sink (menu);
g_signal_handlers_disconnect_by_func (menu, g_object_unref, self);
g_signal_connect (G_OBJECT (menu), "unmap", G_CALLBACK (g_object_unref), self);
gtk_menu_set_screen (GTK_MENU (menu), gdk_screen_get_default ());
gtk_widget_show (menu);
GtkMenuPositionFunc position = button ? NULL : top_window_action_menu;
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, position, self, button, time);
}
static void
handle_window_closed (WnckScreen *screen,
WnckWindow *window,
BamfLegacyWindow *self)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
g_return_if_fail (WNCK_IS_WINDOW (window));
if (self->priv->legacy_window == window)
{
self->priv->is_closed = TRUE;
g_signal_emit (self, legacy_window_signals[CLOSED], 0);
}
}
static void
handle_destroy_notify (gpointer *data, BamfLegacyWindow *self_was_here)
{
BamfLegacyScreen *screen = bamf_legacy_screen_get_default ();
bamf_legacy_screen_inject_window (screen, GPOINTER_TO_UINT (data));
}
/* This utility function allows to set a BamfLegacyWindow as closed, notifying
* all its owners, and to reopen it once the current window has been destroyed.
* This allows to remap particular windows to different applications. */
void
bamf_legacy_window_reopen (BamfLegacyWindow *self)
{
g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->reopen)
return BAMF_LEGACY_WINDOW_GET_CLASS (self)->reopen (self);
g_return_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window));
guint xid = bamf_legacy_window_get_xid (self);
/* Adding a weak ref to this object, causes to get notified after the object
* destruction, so once this BamfLegacyWindow has been closed and destroyed
* the handle_destroy_notify() function will be called, and that will
* provide to inject another window like this one to the BamfLegacyScreen */
g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify,
GUINT_TO_POINTER (xid));
self->priv->is_closed = TRUE;
g_signal_emit (self, legacy_window_signals[CLOSED], 0);
}
static void
bamf_legacy_window_dispose (GObject *object)
{
BamfLegacyWindow *self;
guint i;
self = BAMF_LEGACY_WINDOW (object);
if (self->priv->mini_icon)
{
g_file_delete (self->priv->mini_icon, NULL, NULL);
g_clear_object (&self->priv->mini_icon);
}
g_clear_pointer (&self->priv->exec_string, g_free);
g_clear_pointer (&self->priv->working_dir, g_free);
g_signal_handlers_disconnect_by_data (wnck_screen_get_default (), self);
if (self->priv->legacy_window)
{
g_object_set_data (G_OBJECT (self->priv->legacy_window), WNCK_WINDOW_BAMF_DATA, NULL);
g_signal_handlers_disconnect_by_data (self->priv->legacy_window, self);
for (i = 0; i < LAST_SIGNAL; ++i)
{
g_signal_handlers_disconnect_by_func (self->priv->legacy_window,
handle_window_signal,
GUINT_TO_POINTER (NAME_CHANGED));
}
self->priv->legacy_window = NULL;
}
if (self->priv->action_menu)
{
g_signal_handlers_disconnect_by_data (self->priv->action_menu, self);
g_object_remove_weak_pointer (G_OBJECT (self->priv->action_menu),
(gpointer*) &self->priv->action_menu);
}
G_OBJECT_CLASS (bamf_legacy_window_parent_class)->dispose (object);
}
static void
bamf_legacy_window_init (BamfLegacyWindow * self)
{
self->priv = BAMF_LEGACY_WINDOW_GET_PRIVATE (self);
g_signal_connect (wnck_screen_get_default (), "window-closed",
(GCallback) handle_window_closed, self);
}
static void
bamf_legacy_window_class_init (BamfLegacyWindowClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = bamf_legacy_window_dispose;
g_type_class_add_private (klass, sizeof (BamfLegacyWindowPrivate));
legacy_window_signals [NAME_CHANGED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_NAME_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, name_changed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
legacy_window_signals [ROLE_CHANGED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_ROLE_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, role_changed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
legacy_window_signals [CLASS_CHANGED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_CLASS_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, class_changed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
legacy_window_signals [STATE_CHANGED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_STATE_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, state_changed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
legacy_window_signals [GEOMETRY_CHANGED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_GEOMETRY_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, geometry_changed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
legacy_window_signals [CLOSED] =
g_signal_new (BAMF_LEGACY_WINDOW_SIGNAL_CLOSED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyWindowClass, closed),
NULL, NULL, NULL, G_TYPE_NONE, 0);
}
BamfLegacyWindow *
bamf_legacy_window_new (WnckWindow *legacy_window)
{
BamfLegacyWindow *self;
self = (BamfLegacyWindow *) g_object_new (BAMF_TYPE_LEGACY_WINDOW, NULL);
self->priv->legacy_window = legacy_window;
g_return_val_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window), self);
g_warn_if_fail (!g_object_get_data (G_OBJECT (legacy_window), WNCK_WINDOW_BAMF_DATA));
g_object_set_data (G_OBJECT (legacy_window), WNCK_WINDOW_BAMF_DATA, self);
g_signal_connect (G_OBJECT (legacy_window), "name-changed",
G_CALLBACK (handle_window_signal),
GUINT_TO_POINTER (NAME_CHANGED));
g_signal_connect (G_OBJECT (legacy_window), "role-changed",
G_CALLBACK (handle_window_signal),
GUINT_TO_POINTER (ROLE_CHANGED));
g_signal_connect (G_OBJECT (legacy_window), "class-changed",
G_CALLBACK (handle_window_signal),
GUINT_TO_POINTER (CLASS_CHANGED));
g_signal_connect (G_OBJECT (legacy_window), "geometry-changed",
G_CALLBACK (handle_window_signal),
GUINT_TO_POINTER (GEOMETRY_CHANGED));
g_signal_connect (G_OBJECT (legacy_window), "state-changed",
G_CALLBACK (handle_state_changed), self);
return self;
}
./src/bamf-legacy-window.h 0000644 0000156 0000165 00000020760 12704153443 015521 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#ifndef __BAMFLEGACY_WINDOW_H__
#define __BAMFLEGACY_WINDOW_H__
#include "config.h"
#include "bamf-view.h"
#include
#include
#include
#include
#define BAMF_TYPE_LEGACY_WINDOW (bamf_legacy_window_get_type ())
#define BAMF_LEGACY_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_LEGACY_WINDOW, BamfLegacyWindow))
#define BAMF_IS_LEGACY_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_LEGACY_WINDOW))
#define BAMF_LEGACY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_LEGACY_WINDOW, BamfLegacyWindowClass))
#define BAMF_IS_LEGACY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_LEGACY_WINDOW))
#define BAMF_LEGACY_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_LEGACY_WINDOW, BamfLegacyWindowClass))
#define BAMF_LEGACY_WINDOW_SIGNAL_NAME_CHANGED "name-changed"
#define BAMF_LEGACY_WINDOW_SIGNAL_ROLE_CHANGED "role-changed"
#define BAMF_LEGACY_WINDOW_SIGNAL_CLASS_CHANGED "class-changed"
#define BAMF_LEGACY_WINDOW_SIGNAL_STATE_CHANGED "state-changed"
#define BAMF_LEGACY_WINDOW_SIGNAL_GEOMETRY_CHANGED "geometry-changed"
#define BAMF_LEGACY_WINDOW_SIGNAL_CLOSED "closed"
typedef struct _BamfLegacyWindow BamfLegacyWindow;
typedef struct _BamfLegacyWindowClass BamfLegacyWindowClass;
typedef struct _BamfLegacyWindowPrivate BamfLegacyWindowPrivate;
typedef enum
{
BAMF_WINDOW_NORMAL, /* document/app window */
BAMF_WINDOW_DESKTOP, /* desktop background */
BAMF_WINDOW_DOCK, /* panel */
BAMF_WINDOW_DIALOG, /* dialog */
BAMF_WINDOW_TOOLBAR, /* tearoff toolbar */
BAMF_WINDOW_MENU, /* tearoff menu */
BAMF_WINDOW_UTILITY, /* palette/toolbox window */
BAMF_WINDOW_SPLASHSCREEN /* splash screen */
} BamfWindowType;
typedef enum
{
BAMF_WINDOW_FLOATING,
BAMF_WINDOW_HORIZONTAL_MAXIMIZED,
BAMF_WINDOW_VERTICAL_MAXIMIZED,
BAMF_WINDOW_MAXIMIZED
} BamfWindowMaximizationType;
struct _BamfLegacyWindowClass
{
GObjectClass parent;
BamfLegacyWindow * (*get_transient) (BamfLegacyWindow *legacy_window);
const char * (*get_name) (BamfLegacyWindow *legacy_window);
const char * (*get_role) (BamfLegacyWindow *legacy_window);
const char * (*get_class_name) (BamfLegacyWindow *legacy_window);
const char * (*get_class_instance_name) (BamfLegacyWindow *legacy_window);
const char * (*get_exec_string) (BamfLegacyWindow *legacy_window);
const char * (*get_working_dir) (BamfLegacyWindow *legacy_window);
char * (*save_mini_icon) (BamfLegacyWindow *legacy_window);
char * (*get_process_name) (BamfLegacyWindow *legacy_window);
char * (*get_app_id) (BamfLegacyWindow *legacy_window);
char * (*get_unique_bus_name) (BamfLegacyWindow *legacy_window);
char * (*get_menu_object_path) (BamfLegacyWindow *legacy_window);
char * (*get_hint) (BamfLegacyWindow *legacy_window,
const gchar *name);
guint (*get_pid) (BamfLegacyWindow *legacy_window);
guint32 (*get_xid) (BamfLegacyWindow *legacy_window);
gboolean (*needs_attention) (BamfLegacyWindow *legacy_window);
gboolean (*is_active) (BamfLegacyWindow *legacy_window);
gboolean (*is_skip_tasklist) (BamfLegacyWindow *legacy_window);
gboolean (*is_desktop) (BamfLegacyWindow *legacy_window);
gboolean (*is_dialog) (BamfLegacyWindow *legacy_window);
gboolean (*is_closed) (BamfLegacyWindow *legacy_window);
BamfWindowMaximizationType (*maximized) (BamfLegacyWindow *legacy_window);
BamfWindowType (*get_window_type) (BamfLegacyWindow *legacy_window);
void (*get_geometry) (BamfLegacyWindow *legacy_window,
gint *x, gint *y, gint *w, gint *h);
void (*set_hint) (BamfLegacyWindow *legacy_window,
const gchar *name, const gchar *value);
GtkWidget * (*get_action_menu) (BamfLegacyWindow *legacy_window);
void (*show_action_menu) (BamfLegacyWindow *legacy_window,
guint32 time, guint button, gint x, gint y);
void (*reopen) (BamfLegacyWindow *legacy_window);
/*< signals >*/
void (*name_changed) (BamfLegacyWindow *legacy_window);
void (*class_changed) (BamfLegacyWindow *legacy_window);
void (*role_changed) (BamfLegacyWindow *legacy_window);
void (*state_changed) (BamfLegacyWindow *legacy_window);
void (*geometry_changed) (BamfLegacyWindow *legacy_window);
void (*closed) (BamfLegacyWindow *legacy_window);
};
struct _BamfLegacyWindow
{
GObject parent;
/* private */
BamfLegacyWindowPrivate *priv;
};
GType bamf_legacy_window_get_type (void) G_GNUC_CONST;
guint32 bamf_legacy_window_get_xid (BamfLegacyWindow *self);
guint bamf_legacy_window_get_pid (BamfLegacyWindow *self);
void bamf_legacy_window_get_geometry (BamfLegacyWindow *self,
gint *x, gint *y,
gint *width, gint *height);
gboolean bamf_legacy_window_is_active (BamfLegacyWindow *self);
gboolean bamf_legacy_window_is_skip_tasklist (BamfLegacyWindow *self);
gboolean bamf_legacy_window_needs_attention (BamfLegacyWindow *self);
gboolean bamf_legacy_window_is_closed (BamfLegacyWindow *self);
BamfWindowType bamf_legacy_window_get_window_type (BamfLegacyWindow *self);
BamfWindowMaximizationType bamf_legacy_window_maximized (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_class_instance_name (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_class_name (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_name (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_role (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_exec_string (BamfLegacyWindow *self);
const char * bamf_legacy_window_get_working_dir (BamfLegacyWindow *self);
char * bamf_legacy_window_save_mini_icon (BamfLegacyWindow *self);
GFile * bamf_legacy_window_get_saved_mini_icon (BamfLegacyWindow *self);
char * bamf_legacy_window_get_process_name (BamfLegacyWindow *self);
BamfLegacyWindow * bamf_legacy_window_get_transient (BamfLegacyWindow *self);
char * bamf_legacy_window_get_hint (BamfLegacyWindow *self,
const char *name);
void bamf_legacy_window_set_hint (BamfLegacyWindow *self,
const char *name,
const char *value);
gint bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self);
GtkWidget * bamf_legacy_window_get_action_menu (BamfLegacyWindow *self);
void bamf_legacy_window_show_action_menu (BamfLegacyWindow *self,
guint32 time, guint button,
gint x, gint y);
void bamf_legacy_window_reopen (BamfLegacyWindow *self);
BamfLegacyWindow * bamf_legacy_window_new (WnckWindow *legacy_window);
#endif
./src/Makefile.am 0000644 0000156 0000165 00000002753 12704153443 013732 0 ustar jenkins jenkins LIBBAMF_PRIVATE_LIB = $(top_builddir)/lib/libbamf-private/libbamf-private.la
bamfdaemondir = $(pkglibexecdir)
bamfdaemon_PROGRAMS = \
bamfdaemon \
$(NULL)
bamfdaemon_sources = \
main.c \
bamf-daemon.c \
bamf-legacy-window.c \
bamf-legacy-window-test.c \
bamf-legacy-screen.c \
bamf-view.c \
bamf-control.c \
bamf-matcher.c \
bamf-application.c \
bamf-window.c \
bamf-tab.c \
bamf-xutils.c \
$(NULL)
bamfdaemon_headers = \
main.h \
bamf-daemon.h \
bamf-legacy-window.h \
bamf-legacy-window-test.h \
bamf-legacy-screen.h \
bamf-legacy-screen-private.h \
bamf-view.h \
bamf-control.h \
bamf-matcher.h \
bamf-matcher-private.h \
bamf-window.h \
bamf-application.h \
bamf-tab.h \
bamf-xutils.h \
$(NULL)
bamfdaemon_SOURCES = \
$(bamfdaemon_sources) \
$(bamfdaemon_headers) \
$(NULL)
bamfdaemon_LDADD = \
$(LIBBAMF_PRIVATE_LIB) \
$(X_LIBS) \
$(GLIB_LIBS) \
$(GTK_LIBS) \
$(SN_LIBS) \
$(WNCK_LIBS) \
$(GTOP_LIBS) \
$(NULL)
bamfdaemon_CFLAGS = \
-Wall -std=c99 \
-DDATADIR=\""$(datadir)"\" \
-DWNCK_I_KNOW_THIS_IS_UNSTABLE \
-I$(srcdir) \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(SN_CFLAGS) \
$(WNCK_CFLAGS) \
$(GTOP_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(NULL)
if EXPORT_ACTIONS_MENU
bamfdaemon_LDADD += $(DBUSMENU_LIBS)
bamfdaemon_CFLAGS += $(DBUSMENU_CFLAGS)
bamfdaemon_CFLAGS += -DEXPORT_ACTIONS_MENU
endif
bamfdaemon_LDFLAGS = \
-Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions \
$(COVERAGE_LDFLAGS) \
$(NULL)
./src/bamf-control.h 0000644 0000156 0000165 00000005077 12704153435 014435 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMFCONTROL_H__
#define __BAMFCONTROL_H__
#include
#include
#include
#define BAMF_TYPE_CONTROL (bamf_control_get_type ())
#define BAMF_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_CONTROL, BamfControl))
#define BAMF_IS_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_CONTROL))
#define BAMF_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_CONTROL, BamfControlClass))
#define BAMF_IS_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_CONTROL))
#define BAMF_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_CONTROL, BamfControlClass))
typedef struct _BamfControl BamfControl;
typedef struct _BamfControlClass BamfControlClass;
typedef struct _BamfControlPrivate BamfControlPrivate;
struct _BamfControlClass
{
BamfDBusControlSkeletonClass parent;
};
struct _BamfControl
{
BamfDBusControlSkeleton parent;
/* private */
BamfControlPrivate *priv;
};
GType bamf_control_get_type (void) G_GNUC_CONST;
void bamf_control_register_application_for_pid (BamfControl *control,
const char *application,
gint32 pid);
void bamf_control_insert_desktop_file (BamfControl *control,
const char *path);
void bamf_control_create_local_desktop_file (BamfControl *control,
const char *desktop_file);
void bamf_control_quit (BamfControl *control);
BamfControl * bamf_control_get_default (void);
#endif
./src/bamf-xutils.c 0000644 0000156 0000165 00000013535 12704153443 014275 0 ustar jenkins jenkins /*
* 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "bamf-xutils.h"
#include
#include
static Display *
get_xdisplay (gboolean *opened)
{
Display *xdisplay;
xdisplay = gdk_x11_get_default_xdisplay ();
if (opened)
*opened = FALSE;
if (!xdisplay)
{
xdisplay = XOpenDisplay (NULL);
if (xdisplay)
{
if (opened)
*opened = TRUE;
}
}
return xdisplay;
}
static gboolean
gdk_error_trap_pop_and_print (Display *dpy)
{
gdk_flush ();
gint error_code = gdk_error_trap_pop ();
if (error_code)
{
gchar tmp[1024];
XGetErrorText (dpy, error_code, tmp, sizeof (tmp) - 1);
tmp[sizeof (tmp) - 1] = '\0';
g_warning ("Got an X error: %s\n", tmp);
return TRUE;
}
return FALSE;
}
static void
bamf_xutils_get_string_window_hint_and_type (Window xid, const char *atom_name,
gchar** return_hint, Atom* return_type)
{
Display *XDisplay;
gint format;
gulong numItems;
gulong bytesAfter;
Atom type;
unsigned char *buffer;
gboolean close_display;
if (return_hint)
*return_hint = NULL;
if (return_type)
*return_type = AnyPropertyType;
g_return_if_fail (xid != 0);
g_return_if_fail (return_hint || return_type);
close_display = FALSE;
XDisplay = get_xdisplay (&close_display);
if (!XDisplay)
{
g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
return;
}
gdk_error_trap_push ();
int result = XGetWindowProperty (XDisplay, xid,
gdk_x11_get_xatom_by_name (atom_name),
0, G_MAXINT, False, AnyPropertyType,
&type, &format, &numItems,
&bytesAfter, &buffer);
gboolean x_error = gdk_error_trap_pop_and_print (XDisplay);
if (close_display)
XCloseDisplay (XDisplay);
if (x_error)
{
XFree (buffer);
return;
}
if (result == Success && numItems > 0)
{
if (return_type)
*return_type = type;
if (return_hint && buffer && buffer[0] != '\0')
{
if (type == XA_STRING || type == gdk_x11_get_xatom_by_name ("UTF8_STRING"))
*return_hint = g_strdup ((char*) buffer);
}
XFree (buffer);
}
}
char *
bamf_xutils_get_string_window_hint (Window xid, const char *atom_name)
{
gchar *hint = NULL;
bamf_xutils_get_string_window_hint_and_type (xid, atom_name, &hint, NULL);
return hint;
}
void
bamf_xutils_set_string_window_hint (Window xid, const char *atom_name, const char *value)
{
Display *XDisplay;
Atom type;
gboolean close_display = FALSE;
g_return_if_fail (xid != 0);
g_return_if_fail (atom_name);
g_return_if_fail (value);
XDisplay = get_xdisplay (&close_display);
if (!XDisplay)
{
g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
return;
}
bamf_xutils_get_string_window_hint_and_type (xid, atom_name, NULL, &type);
if (type == AnyPropertyType)
{
type = XA_STRING;
}
else if (type != XA_STRING && type != gdk_x11_get_xatom_by_name ("UTF8_STRING"))
{
g_error ("Impossible to set the atom %s on Window %lu", atom_name, xid);
if (close_display)
XCloseDisplay (XDisplay);
return;
}
gdk_error_trap_push ();
XChangeProperty (XDisplay, xid, gdk_x11_get_xatom_by_name (atom_name),
type, 8, PropModeReplace, (unsigned char *) value, strlen (value));
gdk_error_trap_pop_and_print (XDisplay);
if (close_display)
XCloseDisplay (XDisplay);
}
void
bamf_xutils_unset_window_hint (Window xid, const char *atom_name)
{
Display *XDisplay;
gboolean close_display = FALSE;
g_return_if_fail (xid != 0);
g_return_if_fail (atom_name);
XDisplay = get_xdisplay (&close_display);
if (!XDisplay)
{
g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
return;
}
gdk_error_trap_push ();
XDeleteProperty (XDisplay, xid, gdk_x11_get_xatom_by_name (atom_name));
gdk_error_trap_pop_and_print (XDisplay);
if (close_display)
XCloseDisplay (XDisplay);
}
void
bamf_xutils_get_window_class_hints (Window xid, char **class_instance_name, char **class_name)
{
Display *xdisplay;
gboolean close_display = FALSE;
xdisplay = get_xdisplay (&close_display);
if (!xdisplay)
{
g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
return;
}
XClassHint class_hint;
class_hint.res_name = NULL;
class_hint.res_class = NULL;
gdk_error_trap_push ();
XGetClassHint (xdisplay, xid, &class_hint);
if (!gdk_error_trap_pop_and_print (xdisplay))
{
if (class_name && class_hint.res_class && class_hint.res_class[0] != 0)
*class_name = g_convert (class_hint.res_class, -1, "utf-8", "iso-8859-1",
NULL, NULL, NULL);
if (class_instance_name && class_hint.res_name && class_hint.res_name[0] != 0)
*class_instance_name = g_convert (class_hint.res_name, -1, "utf-8", "iso-8859-1",
NULL, NULL, NULL);
}
XFree (class_hint.res_class);
XFree (class_hint.res_name);
if (close_display)
XCloseDisplay (xdisplay);
}
./src/bamf-daemon.c 0000644 0000156 0000165 00000011515 12704153435 014205 0 ustar jenkins jenkins /*
* Copyright (C) 2011 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: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "bamf-daemon.h"
#include "bamf-matcher.h"
#include "bamf-control.h"
G_DEFINE_TYPE (BamfDaemon, bamf_daemon, G_TYPE_OBJECT);
#define BAMF_DAEMON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_DAEMON, BamfDaemonPrivate))
static BamfDaemon *instance = NULL;
struct _BamfDaemonPrivate
{
BamfMatcher *matcher;
BamfControl *control;
GMainLoop *loop;
};
gboolean
bamf_daemon_is_running (BamfDaemon *self)
{
g_return_val_if_fail (self, FALSE);
if (self->priv->loop && g_main_loop_is_running (self->priv->loop))
{
return TRUE;
}
return FALSE;
}
static void
bamf_on_bus_acquired (GDBusConnection *connection, const gchar *name,
BamfDaemon *self)
{
GError *error = NULL;
g_return_if_fail (BAMF_IS_DAEMON (self));
g_debug ("Acquired a message bus connection");
g_dbus_connection_set_exit_on_close (connection, TRUE);
self->priv->matcher = bamf_matcher_get_default ();
self->priv->control = bamf_control_get_default ();
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->priv->matcher),
connection,
BAMF_DBUS_MATCHER_PATH,
&error);
if (error)
{
g_critical ("Can't register BAMF matcher at path %s: %s", BAMF_DBUS_MATCHER_PATH,
error->message);
g_clear_error (&error);
}
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->priv->control),
connection,
BAMF_DBUS_CONTROL_PATH,
&error);
if (error)
{
g_critical ("Can't register BAMF control at path %s: %s", BAMF_DBUS_CONTROL_PATH,
error->message);
g_clear_error (&error);
}
}
static void
bamf_on_name_acquired (GDBusConnection *connection, const gchar *name,
BamfDaemon *self)
{
g_debug ("Acquired the name %s", name);
}
static void
bamf_on_name_lost (GDBusConnection *connection, const gchar *name, BamfDaemon *self)
{
g_critical ("Lost the name %s, another BAMF daemon is currently running", name);
bamf_daemon_stop (self);
}
void
bamf_daemon_start (BamfDaemon *self)
{
g_return_if_fail (BAMF_IS_DAEMON (self));
if (bamf_daemon_is_running (self))
return;
g_bus_own_name (G_BUS_TYPE_SESSION, BAMF_DBUS_SERVICE_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
(GBusAcquiredCallback) bamf_on_bus_acquired,
(GBusNameAcquiredCallback) bamf_on_name_acquired,
(GBusNameLostCallback) bamf_on_name_lost,
self, NULL);
g_main_loop_run (self->priv->loop);
}
void
bamf_daemon_stop (BamfDaemon *self)
{
g_return_if_fail (BAMF_IS_DAEMON (self));
if (self->priv->matcher)
{
g_object_unref (self->priv->matcher);
self->priv->matcher = NULL;
}
if (self->priv->control)
{
g_object_unref (self->priv->control);
self->priv->control = NULL;
}
g_main_loop_quit (self->priv->loop);
}
static void
bamf_daemon_dispose (GObject *object)
{
BamfDaemon *self = BAMF_DAEMON (object);
bamf_daemon_stop (self);
if (self->priv->loop)
{
g_main_loop_unref (self->priv->loop);
self->priv->loop = NULL;
}
G_OBJECT_CLASS (bamf_daemon_parent_class)->dispose (object);
}
static void
bamf_daemon_finalize (GObject *object)
{
instance = NULL;
}
static void
bamf_daemon_init (BamfDaemon *self)
{
BamfDaemonPrivate *priv;
priv = self->priv = BAMF_DAEMON_GET_PRIVATE (self);
priv->loop = g_main_loop_new (NULL, FALSE);
}
static void
bamf_daemon_class_init (BamfDaemonClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = bamf_daemon_dispose;
object_class->finalize = bamf_daemon_finalize;
g_type_class_add_private (klass, sizeof (BamfDaemonPrivate));
}
BamfDaemon *
bamf_daemon_get_default (void)
{
if (!BAMF_IS_DAEMON (instance))
instance = (BamfDaemon *) g_object_new (BAMF_TYPE_DAEMON, NULL);
return instance;
}
./src/bamf-application.h 0000644 0000156 0000165 00000012244 12704153435 015252 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMFAPPLICATION_H__
#define __BAMFAPPLICATION_H__
#include "bamf-view.h"
#include "bamf-window.h"
#include
#include
#define BAMF_TYPE_APPLICATION (bamf_application_get_type ())
#define BAMF_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_APPLICATION, BamfApplication))
#define BAMF_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_APPLICATION))
#define BAMF_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_APPLICATION, BamfApplicationClass))
#define BAMF_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_APPLICATION))
#define BAMF_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_APPLICATION, BamfApplicationClass))
typedef struct _BamfApplication BamfApplication;
typedef struct _BamfApplicationClass BamfApplicationClass;
typedef struct _BamfApplicationPrivate BamfApplicationPrivate;
struct _BamfApplicationClass
{
BamfViewClass parent;
void (*get_application_menu) (BamfApplication *application, gchar **name, gchar **path);
BamfView* (*get_focusable_child) (BamfApplication *application);
char ** (*get_supported_mime_types) (BamfApplication *application);
gboolean (*get_close_when_empty) (BamfApplication *application);
void (*supported_mimes_changed) (BamfApplication *application, const gchar **mimes);
};
struct _BamfApplication
{
BamfView parent;
/* private */
BamfApplicationPrivate *priv;
};
typedef enum
{
BAMF_APPLICATION_SYSTEM, /* BamfWindow container */
BAMF_APPLICATION_WEB, /* BamfTab container */
BAMF_APPLICATION_UNKNOWN,
} BamfApplicationType;
GType bamf_application_get_type (void) G_GNUC_CONST;
void bamf_application_emit_supported_mime_types_changed (BamfApplication *application);
const char * bamf_application_get_desktop_file (BamfApplication *application);
void bamf_application_set_desktop_file (BamfApplication *application,
const char * desktop_file);
char ** bamf_application_get_supported_mime_types (BamfApplication *application);
GVariant * bamf_application_get_xids (BamfApplication *application);
gboolean bamf_application_manages_xid (BamfApplication *application,
guint32 xid);
BamfWindow * bamf_application_get_window (BamfApplication *application,
guint32 xid);
gboolean bamf_application_contains_similar_to_window (BamfApplication *app,
BamfWindow *window);
gboolean bamf_application_create_local_desktop_file (BamfApplication *app);
const char * bamf_application_get_wmclass (BamfApplication *application);
void bamf_application_set_wmclass (BamfApplication *application,
const char *wmclass);
BamfApplication * bamf_application_new (void);
BamfApplication * bamf_application_new_from_desktop_file (const char * desktop_file);
gboolean bamf_application_get_show_stubs (BamfApplication *application);
BamfApplication * bamf_application_new_from_desktop_files (GList * desktop_files);
BamfApplication * bamf_application_new_with_wmclass (const char *wmclass);
void bamf_application_set_application_type (BamfApplication *application,
BamfApplicationType type);
BamfApplicationType bamf_application_get_application_type (BamfApplication *application);
void bamf_application_get_application_menu (BamfApplication *application,
gchar **name, gchar **object_path);
BamfView * bamf_application_get_focusable_child (BamfApplication *application);
BamfView * bamf_application_get_main_child (BamfApplication *application);
gboolean bamf_application_get_close_when_empty (BamfApplication *application);
gboolean bamf_application_set_desktop_file_from_id (BamfApplication *application, const char *id);
#endif
./src/bamf-xutils.h 0000644 0000156 0000165 00000002310 12704153443 014267 0 ustar jenkins jenkins /*
* 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*/
#ifndef __BAMF_XUTILS_H__
#define __BAMF_XUTILS_H__
#include
#include
#include
void bamf_xutils_set_string_window_hint (Window xid, const char *atom_name, const char *value);
char* bamf_xutils_get_string_window_hint (Window xid, const char *atom_name);
void bamf_xutils_unset_window_hint (Window xid, const char *atom_name);
void bamf_xutils_get_window_class_hints (Window xid, char **class_instance_name, char **class_name);
#endif
./src/bamf-legacy-window-test.h 0000644 0000156 0000165 00000011407 12704153435 016475 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#ifndef __BAMFMOCKWINDOW_H__
#define __BAMFMOCKWINDOW_H__
#include
#include
#include
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-legacy-window.h"
#define BAMF_TYPE_LEGACY_WINDOW_TEST (bamf_legacy_window_test_get_type ())
#define BAMF_LEGACY_WINDOW_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_LEGACY_WINDOW_TEST, BamfLegacyWindowTest))
#define BAMF_LEGACY_WINDOW_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_LEGACY_WINDOW_TEST, BamfLegacyWindowTestClass))
#define BAMF_IS_LEGACY_WINDOW_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_LEGACY_WINDOW_TEST))
#define BAMF_IS_LEGACY_WINDOW_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_LEGACY_WINDOW_TEST))
#define BAMF_LEGACY_WINDOW_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_LEGACY_WINDOW_TEST, BamfLegacyWindowTestClass))
typedef struct _BamfLegacyWindowTest BamfLegacyWindowTest;
typedef struct _BamfLegacyWindowTestClass BamfLegacyWindowTestClass;
struct _BamfLegacyWindowTest
{
BamfLegacyWindow parent;
guint32 xid;
guint pid;
char * name;
char * icon;
char * role;
char * wm_class_name;
char * wm_class_instance;
char * exec;
char * working_dir;
char * process_name;
char * application_id;
char * unique_bus_name;
char * dbus_menu_object_path;
BamfLegacyWindow * transient_window;
gboolean needs_attention;
gboolean is_desktop;
gboolean is_skip;
gboolean is_active;
gboolean is_closed;
GdkRectangle geometry;
BamfWindowMaximizationType maximized;
BamfWindowType window_type;
GHashTable * hints;
};
struct _BamfLegacyWindowTestClass
{
/*< private >*/
BamfLegacyWindowClass parent_class;
void (*_test_padding1) (void);
void (*_test_padding2) (void);
void (*_test_padding3) (void);
void (*_test_padding4) (void);
void (*_test_padding5) (void);
void (*_test_padding6) (void);
};
GType bamf_legacy_window_test_get_type (void) G_GNUC_CONST;
guint
bamf_legacy_window_test_get_pid (BamfLegacyWindow *legacy_window);
guint32
bamf_legacy_window_test_get_xid (BamfLegacyWindow *legacy_window);
void
bamf_legacy_window_test_set_attention (BamfLegacyWindowTest *self, gboolean val);
gboolean
bamf_legacy_window_test_needs_attention (BamfLegacyWindow *legacy_window);
void
bamf_legacy_window_test_set_active (BamfLegacyWindowTest *self, gboolean val);
gboolean
bamf_legacy_window_test_is_active (BamfLegacyWindow *legacy_window);
void
bamf_legacy_window_test_set_desktop (BamfLegacyWindowTest *self, gboolean val);
gboolean
bamf_legacy_window_test_is_desktop (BamfLegacyWindow *legacy_window);
void
bamf_legacy_window_test_set_skip (BamfLegacyWindowTest *self, gboolean val);
gboolean
bamf_legacy_window_test_is_skip_tasklist (BamfLegacyWindow *legacy_window);
void
bamf_legacy_window_test_set_name (BamfLegacyWindowTest *self, const char *val);
void
bamf_legacy_window_test_set_icon (BamfLegacyWindowTest *self, const char *val);
void
bamf_legacy_window_test_set_role (BamfLegacyWindowTest *self, const char *val);
void
bamf_legacy_window_test_set_geometry (BamfLegacyWindowTest *self, int x, int y,
int width, int height);
void
bamf_legacy_window_test_set_maximized (BamfLegacyWindowTest *self,
BamfWindowMaximizationType maximized);
void
bamf_legacy_window_test_set_application_id (BamfLegacyWindowTest *self, const char *id);
void
bamf_legacy_window_test_set_unique_bus_name (BamfLegacyWindowTest *self, const char *bus_name);
void
bamf_legacy_window_test_set_dbus_menu_object_path (BamfLegacyWindowTest *self, const char *object_path);
void
bamf_legacy_window_test_set_wmclass (BamfLegacyWindowTest *self, const char *class_name, const char *instance_name);
void
bamf_legacy_window_test_close (BamfLegacyWindowTest *self);
BamfLegacyWindowTest *
bamf_legacy_window_test_new (guint32 xid, const gchar *name, const gchar *wmclass_name, const gchar *exec);
BamfLegacyWindowTest *
bamf_legacy_window_copy (BamfLegacyWindowTest *self);
#endif
./src/bamf-legacy-screen-private.h 0000644 0000156 0000165 00000002051 12704153435 017133 0 ustar jenkins jenkins /*
* 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: Marco Trevisan (Treviño)
*
*/
#ifndef __BAMF_LEGACY_SCREEN_PRIVATE_H__
#define __BAMF_LEGACY_SCREEN_PRIVATE_H__
#include "bamf-legacy-screen.h"
#include "bamf-legacy-window-test.h"
void _bamf_legacy_screen_open_test_window (BamfLegacyScreen *self, BamfLegacyWindowTest *window);
void _bamf_legacy_screen_close_test_window (BamfLegacyScreen *self, BamfLegacyWindowTest *window);
#endif
./src/simple-state.txt 0000644 0000156 0000165 00000000352 12704153435 015040 0 ustar jenkins jenkins open 234 My Firstish Window gedit gedit %U
open 436 My Second Window gedit gedit %U
open 325 Some Firefox Window firefox firefox %U
close 436
skip 325 true
attention 234 true
open 333 A New Window chromium-browser chromium-browser %U
./src/bamf-application.c 0000644 0000156 0000165 00000124376 12704153447 015262 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-matcher.h"
#include "bamf-legacy-window.h"
#include "bamf-legacy-screen.h"
#include "bamf-tab.h"
#include
#include
#define BAMF_APPLICATION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_APPLICATION, BamfApplicationPrivate))
static void bamf_application_dbus_application_iface_init (BamfDBusItemApplicationIface *iface);
G_DEFINE_TYPE_WITH_CODE (BamfApplication, bamf_application, BAMF_TYPE_VIEW,
G_IMPLEMENT_INTERFACE (BAMF_DBUS_ITEM_TYPE_APPLICATION,
bamf_application_dbus_application_iface_init));
struct _BamfApplicationPrivate
{
BamfDBusItemApplication *dbus_iface;
BamfApplicationType app_type;
BamfView * main_child;
GCancellable * cancellable;
char * desktop_file;
GList * desktop_file_list;
char * wmclass;
char ** mimes;
gboolean show_stubs;
};
enum
{
SUPPORTED_MIMES_CHANGED,
LAST_SIGNAL
};
static guint application_signals[LAST_SIGNAL] = { 0 };
#define STUB_KEY "X-Ayatana-Appmenu-Show-Stubs"
static void on_main_child_name_changed (BamfView *, const gchar *, const gchar *, BamfApplication *);
void
bamf_application_supported_mime_types_changed (BamfApplication *application,
const gchar **new_mimes)
{
gchar **mimes = (gchar **) new_mimes;
if (!new_mimes)
{
gchar *empty[] = {NULL};
mimes = g_strdupv (empty);
}
g_signal_emit_by_name (application->priv->dbus_iface, "supported-mime-types-changed", mimes);
if (!new_mimes)
{
g_strfreev (mimes);
mimes = NULL;
}
if (application->priv->mimes)
g_strfreev (application->priv->mimes);
application->priv->mimes = mimes;
}
static gboolean
bamf_application_default_get_close_when_empty (BamfApplication *application)
{
return TRUE;
}
static gchar **
bamf_application_default_get_supported_mime_types (BamfApplication *application)
{
const char *desktop_file;
char** mimes;
desktop_file = bamf_application_get_desktop_file (application);
if (!desktop_file)
return NULL;
GKeyFile* key_file = g_key_file_new ();
if (!g_key_file_load_from_file (key_file, desktop_file, G_KEY_FILE_NONE, NULL))
{
g_key_file_free (key_file);
return NULL;
}
mimes = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL, NULL);
g_signal_emit (application, application_signals[SUPPORTED_MIMES_CHANGED], 0, mimes);
g_key_file_free (key_file);
return mimes;
}
char **
bamf_application_get_supported_mime_types (BamfApplication *application)
{
gchar **mimes = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
if (application->priv->mimes)
return g_strdupv (application->priv->mimes);
if (BAMF_APPLICATION_GET_CLASS (application)->get_supported_mime_types)
mimes = BAMF_APPLICATION_GET_CLASS (application)->get_supported_mime_types (application);
application->priv->mimes = mimes;
return g_strdupv (mimes);
}
BamfApplicationType
bamf_application_get_application_type (BamfApplication *application)
{
g_return_val_if_fail (BAMF_IS_APPLICATION (application), BAMF_APPLICATION_UNKNOWN);
return application->priv->app_type;
}
void
bamf_application_set_application_type (BamfApplication *application, BamfApplicationType type)
{
g_return_if_fail (BAMF_IS_APPLICATION (application));
g_return_if_fail (type >= 0 && type < BAMF_APPLICATION_UNKNOWN);
application->priv->app_type = type;
}
const char *
bamf_application_get_desktop_file (BamfApplication *application)
{
BamfApplicationPrivate *priv;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
priv = application->priv;
return priv->desktop_file;
}
const char *
bamf_application_get_wmclass (BamfApplication *application)
{
BamfApplicationPrivate *priv;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
priv = application->priv;
return priv->wmclass;
}
static gboolean
icon_name_is_valid (const char *name)
{
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
if (!name || name[0] == '\0')
return FALSE;
if (g_file_test (name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
return TRUE;
// Please note that since gtk 3.14 gtk_icon_theme_has_icon stopped working.
icon_theme = gtk_icon_theme_get_default ();
icon_info = gtk_icon_theme_lookup_icon (icon_theme, name, -1, 0);
if (icon_info != NULL)
{
g_object_unref (icon_info);
return TRUE;
}
return FALSE;
}
static gboolean
icon_name_is_generic (const char *name)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
return !bamf_matcher_is_valid_process_prefix (matcher, name);
}
static void
bamf_application_setup_icon_and_name (BamfApplication *self, gboolean force)
{
BamfWindow *window;
BamfLegacyWindow *legacy_window;
GDesktopAppInfo *desktop;
GKeyFile * keyfile;
GIcon *gicon;
const char *class;
char *icon = NULL, *generic_icon = NULL, *name = NULL;
GError *error;
g_return_if_fail (BAMF_IS_APPLICATION (self));
if (!force)
{
if (bamf_view_get_icon (BAMF_VIEW (self)) && bamf_view_get_name (BAMF_VIEW (self)))
return;
}
if (self->priv->desktop_file)
{
keyfile = g_key_file_new ();
if (!g_key_file_load_from_file (keyfile, self->priv->desktop_file, G_KEY_FILE_NONE, NULL))
{
g_key_file_free (keyfile);
return;
}
desktop = g_desktop_app_info_new_from_keyfile (keyfile);
if (!G_IS_APP_INFO (desktop))
{
g_key_file_free (keyfile);
return;
}
gicon = g_app_info_get_icon (G_APP_INFO (desktop));
name = g_strdup (g_app_info_get_display_name (G_APP_INFO (desktop)));
if (gicon)
{
icon = g_icon_to_string (gicon);
if (!icon_name_is_valid (icon))
{
g_free (icon);
icon = NULL;
}
}
if (!icon)
{
icon = g_strdup (BAMF_APPLICATION_DEFAULT_ICON);
}
if (g_key_file_has_key (keyfile, G_KEY_FILE_DESKTOP_GROUP, STUB_KEY, NULL))
{
/* This will error to return false, which is okay as it seems
unlikely anyone will want to set this flag except to turn
off the stub menus. */
self->priv->show_stubs = g_key_file_get_boolean (keyfile,
G_KEY_FILE_DESKTOP_GROUP,
STUB_KEY, NULL);
}
if (g_key_file_has_key (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_FULLNAME, NULL))
{
/* Grab the better name if its available */
gchar *fullname = NULL;
error = NULL;
fullname = g_key_file_get_locale_string (keyfile,
G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_FULLNAME,
NULL, &error);
if (error != NULL)
{
g_error_free (error);
g_free (fullname);
}
else
{
g_free (name);
name = fullname;
}
}
g_object_unref (desktop);
g_key_file_free (keyfile);
}
else if (BAMF_IS_WINDOW (self->priv->main_child))
{
name = g_strdup (bamf_view_get_name (self->priv->main_child));
window = BAMF_WINDOW (self->priv->main_child);
legacy_window = bamf_window_get_window (window);
class = bamf_legacy_window_get_class_name (legacy_window);
if (class)
{
icon = g_utf8_strdown (class, -1);
if (icon_name_is_valid (icon))
{
if (icon_name_is_generic (icon))
{
generic_icon = icon;
icon = NULL;
}
}
else
{
g_free (icon);
icon = NULL;
}
}
if (!icon)
{
const char *exec = bamf_legacy_window_get_exec_string (legacy_window);
icon = bamf_matcher_get_trimmed_exec (bamf_matcher_get_default (), exec);
if (icon_name_is_valid (icon))
{
if (icon_name_is_generic (icon))
{
g_free (generic_icon);
generic_icon = icon;
icon = NULL;
}
}
else
{
g_free (icon);
icon = NULL;
}
}
if (!icon)
{
icon = bamf_legacy_window_save_mini_icon (legacy_window);
if (!icon)
{
if (generic_icon)
{
icon = generic_icon;
generic_icon = NULL;
}
else
{
icon = g_strdup (BAMF_APPLICATION_DEFAULT_ICON);
}
}
}
g_free (generic_icon);
generic_icon = NULL;
}
bamf_view_set_icon (BAMF_VIEW (self), icon);
bamf_view_set_name (BAMF_VIEW (self), name);
g_free (name);
g_free (icon);
}
void
bamf_application_set_desktop_file (BamfApplication *application,
const char * desktop_file)
{
g_return_if_fail (BAMF_IS_APPLICATION (application));
if (g_strcmp0 (application->priv->desktop_file, desktop_file) == 0)
return;
g_free (application->priv->desktop_file);
application->priv->desktop_file = NULL;
if (desktop_file && desktop_file[0] != '\0')
application->priv->desktop_file = g_strdup (desktop_file);
if (application->priv->main_child)
{
g_signal_handlers_disconnect_by_func (application->priv->main_child,
on_main_child_name_changed, application);
}
g_signal_emit_by_name (application, "desktop-file-updated",
application->priv->desktop_file);
bamf_application_setup_icon_and_name (application, TRUE);
}
gboolean
bamf_application_set_desktop_file_from_id (BamfApplication *application,
const char *desktop_id)
{
GDesktopAppInfo *info;
const char *filename;
info = g_desktop_app_info_new (desktop_id);
if (info == NULL)
{
g_warning ("Failed to load desktop file from desktop ID: %s", desktop_id);
return FALSE;
}
filename = g_desktop_app_info_get_filename (info);
bamf_application_set_desktop_file (application, filename);
g_object_unref (G_OBJECT (info));
return TRUE;
}
static GFile *
try_create_subdir (GFile *parent, const gchar *child_name, GCancellable *cancellable)
{
GFile *child;
GError *error = NULL;
child = g_file_get_child (parent, child_name);
g_return_val_if_fail (G_IS_FILE (child), NULL);
g_file_make_directory_with_parents (child, cancellable, &error);
if (error)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
{
g_error ("Impossible to create `%s` directory: %s", child_name, error->message);
g_clear_object (&child);
}
g_error_free (error);
}
return child;
}
static GFile *
try_create_child (GFile *parent, const gchar *basename, const gchar *extension, GCancellable *cancellable)
{
gchar *down, *child_name;
down = g_ascii_strdown (basename, -1);
g_strdelimit (down, "/\\&%\"'!?`*.;:^|()= <>[]{}", '_');
child_name = g_strconcat (down, extension, NULL);
GFile *child = g_file_get_child (parent, child_name);
g_return_val_if_fail (G_IS_FILE (child), NULL);
if (g_file_query_exists (child, cancellable))
g_clear_object (&child);
g_free (child_name);
g_free (down);
return child;
}
gboolean
try_create_local_desktop_data (GFile *apps_dir, GFile *icons_dir, const char *basename,
GFile **out_desktop_file, GFile **out_icon_file,
GCancellable *cancellable)
{
g_return_val_if_fail (out_desktop_file, FALSE);
if (!apps_dir)
{
*out_desktop_file = NULL;
g_warn_if_reached ();
}
*out_desktop_file = try_create_child (apps_dir, basename, ".desktop", cancellable);
if (G_IS_FILE (*out_desktop_file))
{
if (G_IS_FILE (icons_dir) && out_icon_file)
*out_icon_file = try_create_child (icons_dir, basename, ".png", cancellable);
return TRUE;
}
return FALSE;
}
gboolean
bamf_application_create_local_desktop_file (BamfApplication *self)
{
BamfApplicationPrivate *priv;
BamfLegacyWindow *window;
BamfMatcher *matcher;
GKeyFile *key_file;
const gchar *name, *icon, *iclass, *nclass, *class, *exec, *path, *curdesktop;
GFile *data_dir, *apps_dir, *icons_dir, *desktop_file, *icon_file, *mini_icon;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (self), FALSE);
priv = self->priv;
if (priv->desktop_file || !BAMF_IS_WINDOW (priv->main_child))
{
return FALSE;
}
window = bamf_window_get_window (BAMF_WINDOW (priv->main_child));
exec = bamf_legacy_window_get_exec_string (window);
if (!exec)
{
return FALSE;
}
matcher = bamf_matcher_get_default ();
data_dir = g_file_new_for_path (g_get_user_data_dir ());
name = bamf_view_get_name (BAMF_VIEW (self));
icon = bamf_view_get_icon (BAMF_VIEW (self));
nclass = bamf_legacy_window_get_class_name (window);
iclass = bamf_legacy_window_get_class_instance_name (window);
path = bamf_legacy_window_get_working_dir (window);
mini_icon = bamf_legacy_window_get_saved_mini_icon (window);
curdesktop = g_getenv ("XDG_CURRENT_DESKTOP");
if (!bamf_matcher_is_valid_class_name (matcher, iclass))
iclass = NULL;
if (!bamf_matcher_is_valid_class_name (matcher, nclass))
nclass = NULL;
apps_dir = try_create_subdir (data_dir, "applications", priv->cancellable);
icons_dir = NULL;
if (!G_IS_FILE (apps_dir))
{
g_object_unref (data_dir);
return FALSE;
}
if (icon && G_IS_FILE (mini_icon))
icons_dir = try_create_subdir (data_dir, "icons", priv->cancellable);
g_clear_object (&data_dir);
desktop_file = NULL;
icon_file = NULL;
class = (nclass) ? nclass : iclass;
if (class)
{
try_create_local_desktop_data (apps_dir, icons_dir, class,
&desktop_file, &icon_file, priv->cancellable);
}
if (!G_IS_FILE (desktop_file))
{
gchar *trimmed_exec = bamf_matcher_get_trimmed_exec (matcher, exec);
try_create_local_desktop_data (apps_dir, icons_dir, trimmed_exec,
&desktop_file, &icon_file, priv->cancellable);
g_free (trimmed_exec);
}
if (!G_IS_FILE (desktop_file))
{
try_create_local_desktop_data (apps_dir, icons_dir, exec,
&desktop_file, &icon_file, priv->cancellable);
}
g_object_unref (apps_dir);
if (!G_IS_FILE (desktop_file))
{
g_critical ("Impossible to find a valid path where to save a .desktop file");
g_clear_object (&icons_dir);
g_clear_object (&icon_file);
return FALSE;
}
if (G_IS_FILE (icons_dir) && !G_IS_FILE (icon_file))
{
gchar *basename = g_file_get_basename (mini_icon);
icon_file = try_create_child (icons_dir, basename+1, ".png", priv->cancellable);
g_free (basename);
}
g_clear_object (&icons_dir);
if (G_IS_FILE (icon_file))
{
if (!g_file_copy (mini_icon, icon_file, G_FILE_COPY_NONE,
priv->cancellable, NULL, NULL, &error))
{
g_warning ("Impossible to copy icon to final destination: %s", error->message);
g_clear_error (&error);
g_clear_object (&icon_file);
}
}
key_file = g_key_file_new ();
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
"Encoding", "UTF-8");
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_VERSION, "1.0");
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_TYPE,
G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
if (name)
{
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NAME, name);
}
if (icon_file)
{
gchar *basename = g_file_get_basename (icon_file);
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ICON, basename);
bamf_view_set_icon (BAMF_VIEW (self), basename);
g_free (basename);
g_clear_object (&icon_file);
}
else if (icon)
{
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ICON, icon);
}
if (path && path[0] != '\0')
{
gchar *current_dir = g_get_current_dir ();
if (g_strcmp0 (current_dir, path) != 0)
{
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_PATH, path);
}
g_free (current_dir);
}
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_EXEC, exec);
/* It would be nice to know if the app support it from a win property */
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, FALSE);
if (class)
{
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS, class);
}
if (curdesktop)
{
const gchar* show_in_list[] = { curdesktop, NULL };
g_key_file_set_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN,
show_in_list, 1);
}
gchar *generator = g_strdup_printf ("X-%sGenerated", curdesktop ? curdesktop : "BAMF");
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, generator, TRUE);
g_free (generator);
gsize data_length = 0;
gchar *data = g_key_file_to_data (key_file, &data_length, &error);
g_key_file_free (key_file);
if (error)
{
g_critical ("Impossible to generate local desktop file: %s", error->message);
g_clear_error (&error);
g_clear_pointer (&data, g_free);
}
if (data)
{
g_file_replace_contents (desktop_file, data, data_length, NULL, FALSE,
G_FILE_CREATE_NONE, NULL, priv->cancellable, &error);
g_free (data);
if (error)
{
g_critical ("Impossible to create local desktop file: %s", error->message);
g_clear_error (&error);
g_object_unref (desktop_file);
return FALSE;
}
}
gchar *desktop_path = g_file_get_path (desktop_file);
g_object_unref (desktop_file);
bamf_application_set_desktop_file (self, desktop_path);
g_free (desktop_path);
return TRUE;
}
void
bamf_application_set_wmclass (BamfApplication *application,
const char *wmclass)
{
g_return_if_fail (BAMF_IS_APPLICATION (application));
if (application->priv->wmclass)
g_free (application->priv->wmclass);
if (wmclass && wmclass[0] != '\0')
application->priv->wmclass = g_strdup (wmclass);
else
application->priv->wmclass = NULL;
}
GVariant *
bamf_application_get_xids (BamfApplication *application)
{
GList *l;
GVariantBuilder b;
BamfView *view;
guint32 xid;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(au)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("au"));
for (l = bamf_view_get_children (BAMF_VIEW (application)); l; l = l->next)
{
view = l->data;
if (BAMF_IS_WINDOW (view))
xid = bamf_window_get_xid (BAMF_WINDOW (view));
else if (BAMF_IS_TAB (view))
xid = bamf_tab_get_xid (BAMF_TAB (view));
else
continue;
g_variant_builder_add (&b, "u", xid);
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
gboolean
bamf_application_contains_similar_to_window (BamfApplication *self,
BamfWindow *bamf_window)
{
GList *children, *l;
BamfView *child;
g_return_val_if_fail (BAMF_IS_APPLICATION (self), FALSE);
g_return_val_if_fail (BAMF_IS_WINDOW (bamf_window), FALSE);
BamfLegacyWindow *window = bamf_window_get_window (bamf_window);
const char *window_class = bamf_legacy_window_get_class_name (window);
const char *instance_name = bamf_legacy_window_get_class_instance_name (window);
children = bamf_view_get_children (BAMF_VIEW (self));
for (l = children; l; l = l->next)
{
child = l->data;
if (!BAMF_IS_WINDOW (child))
continue;
window = bamf_window_get_window (BAMF_WINDOW (child));
const char *owned_win_class = bamf_legacy_window_get_class_name (window);
const char *owned_instance = bamf_legacy_window_get_class_instance_name (window);
if (g_strcmp0 (window_class, owned_win_class) == 0 &&
g_strcmp0 (instance_name, owned_instance) == 0)
{
return TRUE;
}
}
return FALSE;
}
gboolean
bamf_application_manages_xid (BamfApplication *application,
guint32 xid)
{
return (bamf_application_get_window (application, xid) != NULL);
}
BamfWindow *
bamf_application_get_window (BamfApplication *application,
guint32 xid)
{
GList *l;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
for (l = bamf_view_get_children (BAMF_VIEW (application)); l; l = l->next)
{
BamfView *view = l->data;
if (!BAMF_IS_WINDOW (view))
continue;
BamfWindow *window = BAMF_WINDOW (view);
if (bamf_window_get_xid (window) == xid)
{
return window;
}
}
return NULL;
}
static const char *
bamf_application_get_view_type (BamfView *view)
{
return "application";
}
static char *
bamf_application_get_stable_bus_name (BamfView *view)
{
BamfApplication *self;
g_return_val_if_fail (BAMF_IS_APPLICATION (view), NULL);
self = BAMF_APPLICATION (view);
if (self->priv->desktop_file)
return g_strdup_printf ("application/%i", abs (g_str_hash (self->priv->desktop_file)));
return g_strdup_printf ("application/%p", view);
}
static void
bamf_application_ensure_flags (BamfApplication *self)
{
gboolean urgent = FALSE, visible = FALSE, running = FALSE, active = FALSE;
GList *l;
BamfView *view;
for (l = bamf_view_get_children (BAMF_VIEW (self)); l; l = l->next)
{
view = l->data;
if (!BAMF_IS_VIEW (view))
continue;
running = TRUE;
if (!BAMF_IS_WINDOW (view) && !BAMF_IS_TAB (view))
continue;
if (bamf_view_is_urgent (view))
urgent = TRUE;
if (bamf_view_is_user_visible (view))
visible = TRUE;
if (bamf_view_is_active (view))
active = TRUE;
if (urgent && visible && active)
break;
}
gboolean close_when_empty = bamf_application_get_close_when_empty (self);
bamf_view_set_urgent (BAMF_VIEW (self), urgent);
bamf_view_set_user_visible (BAMF_VIEW (self), (visible || !close_when_empty));
bamf_view_set_running (BAMF_VIEW (self), (running || !close_when_empty));
bamf_view_set_active (BAMF_VIEW (self), active);
}
static void
view_active_changed (BamfView *view, gboolean active, BamfApplication *self)
{
bamf_application_ensure_flags (self);
}
static void
view_urgent_changed (BamfView *view, gboolean urgent, BamfApplication *self)
{
bamf_application_ensure_flags (self);
}
static void
view_visible_changed (BamfView *view, gboolean visible, BamfApplication *self)
{
bamf_application_ensure_flags (self);
}
static void
view_xid_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
{
BamfApplication *self;
self = (BamfApplication *)user_data;
bamf_application_ensure_flags (self);
}
static void
on_main_child_name_changed (BamfView *child, const gchar *old_name,
const gchar *new_name, BamfApplication *self)
{
bamf_view_set_name (BAMF_VIEW (self), new_name);
}
static void
bamf_application_set_main_child (BamfApplication *self, BamfView *child)
{
if (self->priv->main_child == child)
return;
if (self->priv->main_child)
{
g_object_remove_weak_pointer (G_OBJECT (self->priv->main_child),
(gpointer*) &self->priv->main_child);
g_signal_handlers_disconnect_by_func (self->priv->main_child,
on_main_child_name_changed, self);
}
self->priv->main_child = child;
if (self->priv->main_child)
{
g_object_add_weak_pointer (G_OBJECT (self->priv->main_child),
(gpointer*) &self->priv->main_child);
if (!self->priv->desktop_file)
{
g_signal_connect (child, "name-changed",
G_CALLBACK (on_main_child_name_changed), self);
}
}
}
BamfView *
bamf_application_get_main_child (BamfApplication *self)
{
g_return_val_if_fail (BAMF_IS_APPLICATION (self), NULL);
return self->priv->main_child;
}
static void
bamf_application_child_added (BamfView *view, BamfView *child)
{
BamfApplication *application;
BamfWindow *window = NULL;
gboolean reset_emblems = FALSE;
application = BAMF_APPLICATION (view);
g_signal_connect (G_OBJECT (child), "active-changed",
(GCallback) view_active_changed, view);
g_signal_connect (G_OBJECT (child), "urgent-changed",
(GCallback) view_urgent_changed, view);
g_signal_connect (G_OBJECT (child), "user-visible-changed",
(GCallback) view_visible_changed, view);
if (BAMF_IS_WINDOW (child))
{
window = BAMF_WINDOW (child);
}
else if (BAMF_IS_TAB (child))
{
g_signal_connect (G_OBJECT (child), "notify::xid",
(GCallback) view_xid_changed, view);
}
if (application->priv->main_child)
{
if (window && BAMF_IS_WINDOW (application->priv->main_child))
{
BamfWindow *main_window = BAMF_WINDOW (application->priv->main_child);
if (bamf_window_get_window_type (main_window) != BAMF_WINDOW_NORMAL &&
bamf_window_get_window_type (window) == BAMF_WINDOW_NORMAL)
{
bamf_application_set_main_child (application, child);
}
}
}
else
{
bamf_application_set_main_child (application, child);
}
bamf_application_ensure_flags (BAMF_APPLICATION (view));
if (!application->priv->desktop_file && application->priv->main_child == child)
reset_emblems = TRUE;
bamf_application_setup_icon_and_name (application, reset_emblems);
}
static char *
bamf_application_favorite_from_list (BamfApplication *self, GList *desktop_list)
{
BamfMatcher *matcher;
GList *favs, *l;
char *result = NULL;
const char *desktop_class;
g_return_val_if_fail (BAMF_IS_APPLICATION (self), NULL);
matcher = bamf_matcher_get_default ();
favs = bamf_matcher_get_favorites (matcher);
if (favs)
{
for (l = favs; l; l = l->next)
{
if (g_list_find_custom (desktop_list, l->data, (GCompareFunc) g_strcmp0))
{
desktop_class = bamf_matcher_get_desktop_file_class (matcher, l->data);
if (!desktop_class || g_strcmp0 (self->priv->wmclass, desktop_class) == 0)
{
result = l->data;
break;
}
}
}
}
return result;
}
static void
bamf_application_set_desktop_file_from_list (BamfApplication *self, GList *list)
{
BamfApplicationPrivate *priv;
GList *l;
char *desktop_file;
g_return_if_fail (BAMF_IS_APPLICATION (self));
g_return_if_fail (list);
priv = self->priv;
if (priv->desktop_file_list)
{
g_list_free_full (priv->desktop_file_list, g_free);
priv->desktop_file_list = NULL;
}
for (l = list; l; l = l->next)
priv->desktop_file_list = g_list_prepend (priv->desktop_file_list, g_strdup (l->data));
priv->desktop_file_list = g_list_reverse (priv->desktop_file_list);
desktop_file = bamf_application_favorite_from_list (self, priv->desktop_file_list);
/* items, after reversing them, are in priority order */
if (!desktop_file)
desktop_file = list->data;
bamf_application_set_desktop_file (self, desktop_file);
}
static void
bamf_application_child_removed (BamfView *view, BamfView *child)
{
BamfApplication *self = BAMF_APPLICATION (view);
GList *children, *l;
bamf_application_ensure_flags (self);
children = bamf_view_get_children (view);
if (self->priv->main_child == child)
{
/* Giving priority to older windows, and BamfView has a reversed list */
children = g_list_last (children);
bamf_application_set_main_child (self, (children ? children->data : NULL));
if (self->priv->app_type == BAMF_APPLICATION_SYSTEM)
{
/* We check if we have a better target in next windows */
for (l = children; l; l = l->prev)
{
if (bamf_window_get_window_type (BAMF_WINDOW (l->data)) == BAMF_WINDOW_NORMAL)
{
bamf_application_set_main_child (self, l->data);
break;
}
}
}
if (self->priv->main_child)
{
gboolean reset_emblems = (!self->priv->desktop_file);
bamf_application_setup_icon_and_name (self, reset_emblems);
}
}
if (!children && bamf_application_get_close_when_empty (self))
{
bamf_view_close (view);
}
}
static gboolean
bamf_application_starting_changed (BamfView *view, gboolean starting)
{
if (starting)
{
bamf_view_set_user_visible (view, TRUE);
}
else
{
bamf_application_ensure_flags (BAMF_APPLICATION (view));
if (!bamf_view_is_running (view))
bamf_view_close (view);
}
return TRUE;
}
static void
matcher_favorites_changed (BamfMatcher *matcher, BamfApplication *self)
{
char *new_desktop_file = NULL;
g_return_if_fail (BAMF_IS_APPLICATION (self));
g_return_if_fail (BAMF_IS_MATCHER (matcher));
new_desktop_file = bamf_application_favorite_from_list (self, self->priv->desktop_file_list);
if (new_desktop_file)
{
bamf_application_set_desktop_file (self, new_desktop_file);
}
}
static void
on_child_added (BamfApplication *self, const gchar *child_path, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_APPLICATION (self));
g_signal_emit_by_name (self->priv->dbus_iface, "window-added", child_path);
}
static void
on_child_removed (BamfApplication *self, const gchar *child_path, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_APPLICATION (self));
g_signal_emit_by_name (self->priv->dbus_iface, "window-removed", child_path);
}
static void
on_desktop_file_updated (BamfApplication *self, const gchar *file, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_APPLICATION (self));
g_signal_emit_by_name (self->priv->dbus_iface, "desktop-file-updated", file);
}
static gboolean
on_dbus_handle_show_stubs (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
gboolean show_stubs = bamf_application_get_show_stubs (self);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", show_stubs));
return TRUE;
}
static gboolean
on_dbus_handle_xids (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
GVariant *xids = bamf_application_get_xids (self);
g_dbus_method_invocation_return_value (invocation, xids);
return TRUE;
}
static gboolean
on_dbus_handle_focusable_child (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
GVariant *out_variant;
BamfView *focusable_child;
out_variant = NULL;
focusable_child = bamf_application_get_focusable_child (self);
if (focusable_child == NULL)
{
out_variant = g_variant_new("(s)", "");
}
else
{
const gchar *path;
path = bamf_view_get_path (BAMF_VIEW (focusable_child));
out_variant = g_variant_new("(s)", path);
}
g_dbus_method_invocation_return_value (invocation, out_variant);
return TRUE;
}
static gboolean
on_dbus_handle_desktop_file (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
const char *desktop_file = self->priv->desktop_file ? self->priv->desktop_file : "";
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", desktop_file));
return TRUE;
}
static gboolean
on_dbus_handle_supported_mime_types (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
GVariant *list;
GVariant *value;
gchar **mimes = bamf_application_get_supported_mime_types (self);
if (mimes)
{
list = g_variant_new_strv ((const gchar**) mimes, -1);
g_strfreev (mimes);
}
else
{
list = g_variant_new_strv (NULL, 0);
}
value = g_variant_new ("(@as)", list);
g_dbus_method_invocation_return_value (invocation, value);
return TRUE;
}
static gboolean
on_dbus_handle_application_menu (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
gchar *name, *path;
bamf_application_get_application_menu (self, &name, &path);
name = name ? name : "";
path = path ? path : "";
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(ss)", name, path));
return TRUE;
}
static gboolean
on_dbus_handle_application_type (BamfDBusItemApplication *interface,
GDBusMethodInvocation *invocation,
BamfApplication *self)
{
const char *type = "";
switch (self->priv->app_type)
{
case BAMF_APPLICATION_SYSTEM:
type = "system";
break;
case BAMF_APPLICATION_WEB:
type = "webapp";
break;
default:
type = "unknown";
}
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", type));
return TRUE;
}
static void
bamf_application_dispose (GObject *object)
{
BamfApplication *app;
BamfApplicationPrivate *priv;
app = BAMF_APPLICATION (object);
priv = app->priv;
if (priv->desktop_file)
{
g_free (priv->desktop_file);
priv->desktop_file = NULL;
}
if (priv->desktop_file_list)
{
g_list_free_full (priv->desktop_file_list, g_free);
priv->desktop_file_list = NULL;
}
if (priv->wmclass)
{
g_free (priv->wmclass);
priv->wmclass = NULL;
}
if (priv->main_child)
{
g_object_remove_weak_pointer (G_OBJECT (priv->main_child),
(gpointer*) &priv->main_child);
g_signal_handlers_disconnect_by_data (priv->main_child, app);
priv->main_child = NULL;
}
if (priv->cancellable)
{
g_cancellable_cancel (priv->cancellable);
g_object_unref (priv->cancellable);
priv->cancellable = NULL;
}
g_strfreev (priv->mimes);
priv->mimes = NULL;
g_signal_handlers_disconnect_by_func (G_OBJECT (bamf_matcher_get_default ()),
matcher_favorites_changed, object);
G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);
}
static void
bamf_application_finalize (GObject *object)
{
BamfApplication *self;
self = BAMF_APPLICATION (object);
g_object_unref (self->priv->dbus_iface);
G_OBJECT_CLASS (bamf_application_parent_class)->finalize (object);
}
static void
bamf_application_init (BamfApplication * self)
{
BamfApplicationPrivate *priv;
priv = self->priv = BAMF_APPLICATION_GET_PRIVATE (self);
priv->app_type = BAMF_APPLICATION_SYSTEM;
priv->show_stubs = TRUE;
priv->cancellable = g_cancellable_new ();
/* Initializing the dbus interface */
priv->dbus_iface = _bamf_dbus_item_application_skeleton_new ();
/* We need to connect to the object own signals to redirect them to the dbus
* interface */
g_signal_connect (self, "child-added", G_CALLBACK (on_child_added), NULL);
g_signal_connect (self, "child-removed", G_CALLBACK (on_child_removed), NULL);
g_signal_connect (self, "desktop-file-updated", G_CALLBACK (on_desktop_file_updated), NULL);
/* Registering signal callbacks to reply to dbus method calls */
g_signal_connect (priv->dbus_iface, "handle-show-stubs",
G_CALLBACK (on_dbus_handle_show_stubs), self);
g_signal_connect (priv->dbus_iface, "handle-xids",
G_CALLBACK (on_dbus_handle_xids), self);
g_signal_connect (priv->dbus_iface, "handle-focusable-child",
G_CALLBACK (on_dbus_handle_focusable_child), self);
g_signal_connect (priv->dbus_iface, "handle-desktop-file",
G_CALLBACK (on_dbus_handle_desktop_file), self);
g_signal_connect (priv->dbus_iface, "handle-supported-mime-types",
G_CALLBACK (on_dbus_handle_supported_mime_types), self);
g_signal_connect (priv->dbus_iface, "handle-application-menu",
G_CALLBACK (on_dbus_handle_application_menu), self);
g_signal_connect (priv->dbus_iface, "handle-application-type",
G_CALLBACK (on_dbus_handle_application_type), self);
/* Setting the interface for the dbus object */
_bamf_dbus_item_object_skeleton_set_application (BAMF_DBUS_ITEM_OBJECT_SKELETON (self),
priv->dbus_iface);
g_signal_connect (G_OBJECT (bamf_matcher_get_default ()), "favorites-changed",
(GCallback) matcher_favorites_changed, self);
}
static void
bamf_application_dbus_application_iface_init (BamfDBusItemApplicationIface *iface)
{
}
static void
bamf_application_class_init (BamfApplicationClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
object_class->dispose = bamf_application_dispose;
object_class->finalize = bamf_application_finalize;
view_class->view_type = bamf_application_get_view_type;
view_class->child_added = bamf_application_child_added;
view_class->child_removed = bamf_application_child_removed;
view_class->starting_changed = bamf_application_starting_changed;
view_class->stable_bus_name = bamf_application_get_stable_bus_name;
klass->get_supported_mime_types = bamf_application_default_get_supported_mime_types;
klass->get_close_when_empty = bamf_application_default_get_close_when_empty;
klass->supported_mimes_changed = bamf_application_supported_mime_types_changed;
g_type_class_add_private (klass, sizeof (BamfApplicationPrivate));
application_signals[SUPPORTED_MIMES_CHANGED] =
g_signal_new ("supported-mimes-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfApplicationClass, supported_mimes_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRV);
}
BamfApplication *
bamf_application_new (void)
{
BamfApplication *application;
application = (BamfApplication *) g_object_new (BAMF_TYPE_APPLICATION, NULL);
return application;
}
BamfApplication *
bamf_application_new_from_desktop_file (const char * desktop_file)
{
BamfApplication *application;
application = (BamfApplication *) g_object_new (BAMF_TYPE_APPLICATION, NULL);
bamf_application_set_desktop_file (application, desktop_file);
return application;
}
BamfApplication *
bamf_application_new_from_desktop_files (GList *desktop_files)
{
BamfApplication *application;
application = (BamfApplication *) g_object_new (BAMF_TYPE_APPLICATION, NULL);
bamf_application_set_desktop_file_from_list (application, desktop_files);
return application;
}
BamfApplication *
bamf_application_new_with_wmclass (const char *wmclass)
{
BamfApplication *application;
application = (BamfApplication *) g_object_new (BAMF_TYPE_APPLICATION, NULL);
bamf_application_set_wmclass (application, wmclass);
return application;
}
gboolean
bamf_application_get_show_stubs (BamfApplication *application)
{
g_return_val_if_fail (BAMF_IS_APPLICATION(application), TRUE);
return application->priv->show_stubs;
}
gboolean
bamf_application_get_close_when_empty (BamfApplication *application)
{
g_return_val_if_fail (BAMF_IS_APPLICATION(application), FALSE);
if (BAMF_APPLICATION_GET_CLASS (application)->get_close_when_empty)
{
return BAMF_APPLICATION_GET_CLASS (application)->get_close_when_empty(application);
}
return TRUE;
}
void
bamf_application_get_application_menu (BamfApplication *application, gchar **name, gchar **object_path)
{
g_return_if_fail (BAMF_IS_APPLICATION (application));
if (BAMF_APPLICATION_GET_CLASS (application)->get_application_menu)
{
BAMF_APPLICATION_GET_CLASS (application)->get_application_menu (application, name, object_path);
}
else
{
*name = NULL;
*object_path = NULL;
}
}
BamfView *
bamf_application_get_focusable_child (BamfApplication *application)
{
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
if (BAMF_APPLICATION_GET_CLASS (application)->get_focusable_child)
{
return BAMF_APPLICATION_GET_CLASS (application)->get_focusable_child (application);
}
return NULL;
}
./src/bamf-control.c 0000644 0000156 0000165 00000017437 12704153435 014433 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include
#include "bamf-control.h"
#include "bamf-application.h"
#include "bamf-daemon.h"
#include "bamf-matcher.h"
G_DEFINE_TYPE (BamfControl, bamf_control, BAMF_DBUS_TYPE_CONTROL_SKELETON);
#define BAMF_CONTROL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_CONTROL, BamfControlPrivate))
struct _BamfControlPrivate
{
GDBusConnection *connection;
guint launched_signal;
GList *sources;
};
static void
bamf_control_on_launched_callback (GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
BamfMatcher *matcher;
const gchar *desktop_file;
gint64 pid;
matcher = bamf_matcher_get_default ();
g_variant_get_child (parameters, 0, "^&ay", &desktop_file);
g_variant_get_child (parameters, 2, "x", &pid);
bamf_matcher_set_starting_desktop_file (matcher, desktop_file, TRUE);
bamf_matcher_register_desktop_file_for_pid (matcher, desktop_file, pid);
}
static void
on_bus_connection (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
BamfControl *self;
GError *error = NULL;
g_return_if_fail (BAMF_IS_CONTROL (user_data));
self = BAMF_CONTROL (user_data);
self->priv->connection = g_bus_get_finish (res, &error);
if (error)
{
g_warning ("Got error when connecting to session bus: %s", error->message);
g_clear_error (&error);
self->priv->connection = NULL;
return;
}
self->priv->launched_signal =
g_dbus_connection_signal_subscribe (self->priv->connection, NULL,
"org.gtk.gio.DesktopAppInfo",
"Launched",
"/org/gtk/gio/DesktopAppInfo",
NULL, G_DBUS_SIGNAL_FLAGS_NONE,
bamf_control_on_launched_callback,
self, NULL);
}
static void
bamf_control_constructed (GObject *object)
{
if (G_OBJECT_CLASS (bamf_control_parent_class)->constructed)
G_OBJECT_CLASS (bamf_control_parent_class)->constructed (object);
g_bus_get (G_BUS_TYPE_SESSION, NULL, on_bus_connection, object);
}
static gboolean
on_dbus_handle_quit (BamfDBusControl *interface,
GDBusMethodInvocation *invocation,
BamfControl *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_control_quit (self);
return TRUE;
}
static gboolean
on_dbus_handle_insert_desktop_file (BamfDBusControl *interface,
GDBusMethodInvocation *invocation,
const gchar *desktop_file,
BamfControl *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_control_insert_desktop_file (self, desktop_file);
return TRUE;
}
static gboolean
on_dbus_handle_register_application_for_pid (BamfDBusControl *interface,
GDBusMethodInvocation *invocation,
const gchar *application,
guint pid,
BamfControl *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_control_register_application_for_pid (self, application, pid);
return TRUE;
}
static gboolean
on_dbus_handle_create_local_desktop_file (BamfDBusControl *interface,
GDBusMethodInvocation *invocation,
const gchar *desktop_file,
BamfControl *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_control_create_local_desktop_file (self, desktop_file);
return TRUE;
}
static void
bamf_control_init (BamfControl * self)
{
self->priv = BAMF_CONTROL_GET_PRIVATE (self);
self->priv->sources = NULL;
/* Registering signal callbacks to reply to dbus method calls */
g_signal_connect (self, "handle-quit",
G_CALLBACK (on_dbus_handle_quit), self);
g_signal_connect (self, "handle-om-nom-nom-desktop-file",
G_CALLBACK (on_dbus_handle_insert_desktop_file), self);
g_signal_connect (self, "handle-insert-desktop-file",
G_CALLBACK (on_dbus_handle_insert_desktop_file), self);
g_signal_connect (self, "handle-register-application-for-pid",
G_CALLBACK (on_dbus_handle_register_application_for_pid), self);
g_signal_connect (self, "handle-create-local-desktop-file",
G_CALLBACK (on_dbus_handle_create_local_desktop_file), self);
}
static void
bamf_control_finalize (GObject *object)
{
BamfControl *self = BAMF_CONTROL (object);
if (self->priv->connection)
{
if (self->priv->launched_signal)
{
g_dbus_connection_signal_unsubscribe (self->priv->connection,
self->priv->launched_signal);
}
g_object_unref (self->priv->connection);
}
g_list_free_full (self->priv->sources, g_object_unref);
}
static void
bamf_control_class_init (BamfControlClass * klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
obj_class->constructed = bamf_control_constructed;
obj_class->finalize = bamf_control_finalize;
g_type_class_add_private (klass, sizeof (BamfControlPrivate));
}
void
bamf_control_register_application_for_pid (BamfControl *control,
const char *application,
gint32 pid)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
bamf_matcher_register_desktop_file_for_pid (matcher, application, pid);
}
void
bamf_control_insert_desktop_file (BamfControl *control,
const char *path)
{
BamfMatcher *matcher = bamf_matcher_get_default ();
bamf_matcher_load_desktop_file (matcher, path);
}
void
bamf_control_create_local_desktop_file (BamfControl *control, const char *app_path)
{
BamfMatcher *matcher;
BamfView *view;
g_return_if_fail (BAMF_IS_CONTROL (control));
g_return_if_fail (app_path);
matcher = bamf_matcher_get_default ();
view = bamf_matcher_get_view_by_path (matcher, app_path);
if (BAMF_IS_APPLICATION (view))
bamf_application_create_local_desktop_file (BAMF_APPLICATION (view));
}
static gboolean
bamf_control_on_quit (BamfControl *control)
{
BamfDaemon *daemon = bamf_daemon_get_default ();
bamf_daemon_stop (daemon);
return FALSE;
}
void
bamf_control_quit (BamfControl *control)
{
g_idle_add ((GSourceFunc) bamf_control_on_quit, control);
}
BamfControl *
bamf_control_get_default (void)
{
static BamfControl *control;
if (!BAMF_IS_CONTROL (control))
{
control = (BamfControl *) g_object_new (BAMF_TYPE_CONTROL, NULL);
}
return control;
}
./src/bamf-view.h 0000644 0000156 0000165 00000011064 12704153435 013720 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMFVIEW_H__
#define __BAMFVIEW_H__
#include
#include
#include
#define BAMF_TYPE_VIEW (bamf_view_get_type ())
#define BAMF_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_VIEW, BamfView))
#define BAMF_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_VIEW))
#define BAMF_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_VIEW, BamfViewClass))
#define BAMF_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_VIEW))
#define BAMF_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_VIEW, BamfViewClass))
typedef struct _BamfView BamfView;
typedef struct _BamfViewClass BamfViewClass;
typedef struct _BamfViewPrivate BamfViewPrivate;
struct _BamfViewClass
{
BamfDBusItemObjectSkeletonClass parent;
GList *names;
/*< methods >*/
const char * (*view_type) (BamfView *view);
char * (*stable_bus_name) (BamfView *view);
/*< random stuff >*/
gboolean (* urgent_changed) (BamfView *view, gboolean urgent);
gboolean (* starting_changed) (BamfView *view, gboolean starting);
gboolean (* running_changed) (BamfView *view, gboolean running);
gboolean (* active_changed) (BamfView *view, gboolean active);
gboolean (* user_visible_changed) (BamfView *view, gboolean visible);
gboolean (* closed) (BamfView *view);
void (* child_added) (BamfView *view, BamfView *child);
void (* child_removed) (BamfView *view, BamfView *child);
/*< signals >*/
void (* closed_internal) (BamfView *view);
void (* exported) (BamfView *view);
};
struct _BamfView
{
BamfDBusItemObjectSkeleton parent;
/* private */
BamfViewPrivate *priv;
};
GType bamf_view_get_type (void) G_GNUC_CONST;
void bamf_view_close (BamfView *view);
GVariant * bamf_view_get_children_paths (BamfView *view);
GList * bamf_view_get_children (BamfView *view);
GVariant * bamf_view_get_parent_paths (BamfView *view);
GList * bamf_view_get_parents (BamfView *view);
const char * bamf_view_get_path (BamfView *view);
void bamf_view_add_child (BamfView *view, BamfView *child);
void bamf_view_remove_child (BamfView *view, BamfView *child);
gboolean bamf_view_is_active (BamfView *view);
void bamf_view_set_active (BamfView *view, gboolean active);
gboolean bamf_view_is_starting (BamfView *view);
void bamf_view_set_starting (BamfView *view, gboolean starting);
gboolean bamf_view_is_running (BamfView *view);
void bamf_view_set_running (BamfView *view, gboolean running);
gboolean bamf_view_is_user_visible (BamfView *view);
void bamf_view_set_user_visible (BamfView *view, gboolean user_visible);
gboolean bamf_view_is_urgent (BamfView *view);
void bamf_view_set_urgent (BamfView *view, gboolean urgent);
void bamf_view_set_icon (BamfView *view, const char *icon);
const char * bamf_view_get_icon (BamfView *view);
const char * bamf_view_get_name (BamfView *view);
void bamf_view_set_name (BamfView *view, const char *name);
const char * bamf_view_get_parent_path (BamfView *view);
BamfView * bamf_view_get_parent (BamfView *view);
void bamf_view_set_parent (BamfView *view, BamfView *parent);
const char * bamf_view_get_view_type (BamfView *view);
gboolean bamf_view_is_on_bus (BamfView *view);
const char * bamf_view_export_on_bus (BamfView *view,
GDBusConnection *connection);
#endif
./src/bamf-matcher-private.h 0000644 0000156 0000165 00000003426 12704153435 016044 0 ustar jenkins jenkins /*
* 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: Marco Trevisan (Treviño)
*
*/
#ifndef __BAMF_MATCHER_PRIVATE_H__
#define __BAMF_MATCHER_PRIVATE_H__
#include "bamf-view.h"
#include "bamf-matcher.h"
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-legacy-window.h"
struct _BamfMatcherPrivate
{
GArray * bad_prefixes;
GArray * good_prefixes;
GHashTable * desktop_id_table;
GHashTable * desktop_file_table;
GHashTable * desktop_class_table;
GHashTable * registered_pids;
GHashTable * opened_closed_paths_table;
GList * known_pids;
GList * views;
GList * monitors;
GList * favorites;
GList * no_display_desktop;
BamfView * active_app;
BamfView * active_win;
guint dispatch_changes_id;
};
BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file);
BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid);
char * get_exec_overridden_desktop_file (const char *exec);
gboolean is_autostart_desktop_file (const gchar *desktop_file);
#endif
./src/bamf-tab.c 0000644 0000156 0000165 00000016145 12704153435 013514 0 ustar jenkins jenkins /*
* 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:
* Robert Carr
*
*/
/**
* SECTION:bamf-tab
* @short_description: The base class for browser tabs
*
* #BamfTab is the base class that all tabs need to derive from.
*/
#include "bamf-tab.h"
#define BAMF_TAB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_TAB, BamfTabPrivate))
static void bamf_tab_dbus_iface_init (BamfDBusItemTabIface *iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (BamfTab, bamf_tab, BAMF_TYPE_VIEW,
G_IMPLEMENT_INTERFACE (BAMF_DBUS_ITEM_TYPE_TAB,
bamf_tab_dbus_iface_init));
enum
{
PROP_0,
PROP_LOCATION,
PROP_XID,
PROP_DESKTOP_ID,
PROP_IS_FOREGROUND_TAB
};
struct _BamfTabPrivate
{
BamfDBusItemTab *dbus_iface;
};
static const gchar *
bamf_tab_get_view_type (BamfView *view)
{
return "tab";
}
static char *
bamf_tab_get_stable_bus_name (BamfView *view)
{
return g_strdup_printf ("tab/%u", GPOINTER_TO_UINT (view));
}
static void
bamf_tab_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
BamfTab *self;
self = BAMF_TAB (object);
switch (property_id)
{
case PROP_LOCATION:
g_value_set_string (value, bamf_tab_get_location (self));
break;
case PROP_XID:
g_value_set_uint64 (value, bamf_tab_get_xid (self));
break;
case PROP_DESKTOP_ID:
g_value_set_string (value, bamf_tab_get_desktop_id (self));
break;
case PROP_IS_FOREGROUND_TAB:
g_value_set_boolean (value, bamf_tab_get_is_foreground_tab (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
bamf_tab_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
BamfTab *self;
self = BAMF_TAB (object);
switch (property_id)
{
case PROP_LOCATION:
_bamf_dbus_item_tab_set_location (self->priv->dbus_iface, g_value_get_string (value));
break;
case PROP_DESKTOP_ID:
_bamf_dbus_item_tab_set_desktop_id (self->priv->dbus_iface, g_value_get_string (value));
break;
case PROP_XID:
_bamf_dbus_item_tab_set_xid (self->priv->dbus_iface, g_value_get_uint64 (value));
break;
case PROP_IS_FOREGROUND_TAB:
_bamf_dbus_item_tab_set_is_foreground_tab (self->priv->dbus_iface, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
bamf_tab_finalize (GObject *object)
{
BamfTab *self = BAMF_TAB (object);
g_object_unref (self->priv->dbus_iface);
G_OBJECT_CLASS (bamf_tab_parent_class)->finalize (object);
}
static gboolean
on_dbus_handle_raise (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfTab *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_tab_raise (self);
return TRUE;
}
static gboolean
on_dbus_handle_close (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfTab *self)
{
g_dbus_method_invocation_return_value (invocation, NULL);
bamf_tab_close (self);
return TRUE;
}
static void
bamf_tab_preview_ready (BamfTab *self,
const gchar *preview_data,
gpointer user_data)
{
GDBusMethodInvocation *invocation;
invocation = (GDBusMethodInvocation *)user_data;
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", preview_data));
}
static gboolean
on_dbus_handle_request_preview (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfTab *self)
{
bamf_tab_request_preview (self, bamf_tab_preview_ready, invocation);
return TRUE;
}
static void
bamf_tab_init (BamfTab *self)
{
self->priv = BAMF_TAB_GET_PRIVATE (self);
self->priv->dbus_iface = _bamf_dbus_item_tab_skeleton_new ();
g_signal_connect (self->priv->dbus_iface, "handle-raise",
G_CALLBACK (on_dbus_handle_raise), self);
g_signal_connect (self->priv->dbus_iface, "handle-close",
G_CALLBACK (on_dbus_handle_close), self);
g_signal_connect (self->priv->dbus_iface, "handle-request-preview",
G_CALLBACK (on_dbus_handle_request_preview), self);
_bamf_dbus_item_object_skeleton_set_tab (BAMF_DBUS_ITEM_OBJECT_SKELETON (self),
self->priv->dbus_iface);
}
static void
bamf_tab_dbus_iface_init (BamfDBusItemTabIface *iface)
{
}
static void
bamf_tab_class_init (BamfTabClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
object_class->get_property = bamf_tab_get_property;
object_class->set_property = bamf_tab_set_property;
object_class->finalize = bamf_tab_finalize;
view_class->view_type = bamf_tab_get_view_type;
view_class->stable_bus_name = bamf_tab_get_stable_bus_name;
g_object_class_override_property (object_class, PROP_LOCATION, "location");
g_object_class_override_property (object_class, PROP_DESKTOP_ID, "desktop-id");
g_object_class_override_property (object_class, PROP_XID, "xid");
g_object_class_override_property (object_class, PROP_IS_FOREGROUND_TAB, "is-foreground-tab");
g_type_class_add_private (klass, sizeof (BamfTabPrivate));
}
const gchar *
bamf_tab_get_location (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), NULL);
return _bamf_dbus_item_tab_get_location (self->priv->dbus_iface);
}
const gchar *
bamf_tab_get_desktop_id (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), NULL);
return _bamf_dbus_item_tab_get_desktop_id (self->priv->dbus_iface);
}
guint64
bamf_tab_get_xid (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), 0);
return _bamf_dbus_item_tab_get_xid (self->priv->dbus_iface);
}
gboolean
bamf_tab_get_is_foreground_tab (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), 0);
return _bamf_dbus_item_tab_get_is_foreground_tab (self->priv->dbus_iface);
}
void
bamf_tab_raise (BamfTab *self)
{
g_return_if_fail (BAMF_IS_TAB (self));
BAMF_TAB_GET_CLASS (self)->raise (self);
}
void
bamf_tab_close (BamfTab *self)
{
g_return_if_fail (BAMF_IS_TAB (self));
BAMF_TAB_GET_CLASS (self)->close (self);
}
void
bamf_tab_request_preview (BamfTab *self, BamfTabPreviewReadyCallback callback, gpointer user_data)
{
g_return_if_fail (BAMF_IS_TAB (self));
BAMF_TAB_GET_CLASS (self)->request_preview (self, callback, user_data);
}
./src/main.h 0000644 0000156 0000165 00000001635 12704153435 012772 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __MAIN_H__
#define __MAIN_H__
#include
#include
#include
#include
#include
#include
#endif
./src/bamf-daemon.h 0000644 0000156 0000165 00000003732 12704153435 014214 0 ustar jenkins jenkins /*
* Copyright (C) 2011 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: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMFDAEMON_H__
#define __BAMFDAEMON_H__
#include
#include
#define BAMF_TYPE_DAEMON (bamf_daemon_get_type ())
#define BAMF_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_DAEMON, BamfDaemon))
#define BAMF_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_DAEMON))
#define BAMF_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_DAEMON, BamfDaemonClass))
#define BAMF_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_DAEMON))
#define BAMF_DAEMON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_DAEMON, BamfDaemonClass))
typedef struct _BamfDaemon BamfDaemon;
typedef struct _BamfDaemonClass BamfDaemonClass;
typedef struct _BamfDaemonPrivate BamfDaemonPrivate;
struct _BamfDaemonClass
{
GObjectClass parent;
};
struct _BamfDaemon
{
GObject parent;
/* private */
BamfDaemonPrivate *priv;
};
GType bamf_daemon_get_type (void) G_GNUC_CONST;
void bamf_daemon_start (BamfDaemon *self);
void bamf_daemon_stop (BamfDaemon *self);
gboolean bamf_daemon_is_running (BamfDaemon *self);
BamfDaemon * bamf_daemon_get_default (void);
#endif //__BAMFDAEMON_H__
./src/bamf-window.h 0000644 0000156 0000165 00000005401 12704153443 014252 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#ifndef __BAMFWINDOW_H__
#define __BAMFWINDOW_H__
#include "bamf-view.h"
#include "bamf-legacy-window.h"
#include
#include
#include
#define BAMF_TYPE_WINDOW (bamf_window_get_type ())
#define BAMF_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_WINDOW, BamfWindow))
#define BAMF_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_WINDOW))
#define BAMF_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_WINDOW, BamfWindowClass))
#define BAMF_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_WINDOW))
#define BAMF_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_WINDOW, BamfWindowClass))
typedef struct _BamfWindow BamfWindow;
typedef struct _BamfWindowClass BamfWindowClass;
typedef struct _BamfWindowPrivate BamfWindowPrivate;
struct _BamfWindowClass
{
BamfViewClass parent;
gboolean (*user_visible) (BamfWindow *window);
gboolean (*is_urgent) (BamfWindow *window);
guint32 (*get_xid) (BamfWindow *window);
BamfLegacyWindow * (*get_window) (BamfWindow *window);
};
struct _BamfWindow
{
BamfView parent;
/* private */
BamfWindowPrivate *priv;
};
GType bamf_window_get_type (void) G_GNUC_CONST;
BamfLegacyWindow * bamf_window_get_window (BamfWindow *self);
BamfWindow * bamf_window_get_transient (BamfWindow *self);
const char * bamf_window_get_transient_path (BamfWindow *self);
guint32 bamf_window_get_window_type (BamfWindow *self);
guint32 bamf_window_get_xid (BamfWindow *window);
guint32 bamf_window_get_pid (BamfWindow *window);
gint bamf_window_get_stack_position (BamfWindow *window);
char * bamf_window_get_string_hint (BamfWindow *self, const char* prop);
BamfWindowMaximizationType bamf_window_maximized (BamfWindow *self);
gint bamf_window_get_monitor (BamfWindow *self);
BamfWindow * bamf_window_new (BamfLegacyWindow *window);
#endif
./src/bamf-legacy-screen.c 0000644 0000156 0000165 00000046731 12704153435 015473 0 ustar jenkins jenkins /*
* 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: Jason Smith
*
*/
#include "bamf-legacy-screen.h"
#include "bamf-legacy-screen-private.h"
#include
#include
#define SN_API_NOT_YET_FROZEN
#include
#undef SN_API_NOT_YET_FROZEN
G_DEFINE_TYPE (BamfLegacyScreen, bamf_legacy_screen, G_TYPE_OBJECT);
#define BAMF_LEGACY_SCREEN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_LEGACY_SCREEN, BamfLegacyScreenPrivate))
static BamfLegacyScreen *static_screen = NULL;
enum
{
WINDOW_OPENING,
WINDOW_OPENING_COMPLETED,
WINDOW_OPENING_CANCELED,
WINDOW_OPENED,
WINDOW_CLOSED,
STACKING_CHANGED,
ACTIVE_WINDOW_CHANGED,
LAST_SIGNAL,
};
static guint legacy_screen_signals[LAST_SIGNAL] = { 0 };
static Atom _COMPIZ_TOOLKIT_ACTION = 0;
static Atom _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = 0;
struct _BamfLegacyScreenPrivate
{
WnckScreen * legacy_screen;
SnDisplay * sn_display;
SnMonitorContext * sn_monitor_context;
GList *windows;
GFile *file;
GDataInputStream *stream;
};
static void
handle_window_closed (BamfLegacyWindow *window, BamfLegacyScreen *self)
{
self->priv->windows = g_list_remove (self->priv->windows, window);
g_signal_emit (self, legacy_screen_signals[WINDOW_CLOSED], 0, window);
g_object_unref (window);
}
static gboolean
on_state_file_load_timeout (BamfLegacyScreen *self)
{
BamfLegacyWindow *window;
GDataInputStream *stream;
gchar *line, *name, *class, *exec;
GList *l;
gchar **parts;
gsize parts_size;
guint32 xid;
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (self), FALSE);
stream = self->priv->stream;
line = g_data_input_stream_read_line (stream, NULL, NULL, NULL);
if (!line)
return FALSE;
// Line format:
// open
// close
// attention
// skip
// geometry
// maximized
parts = g_strsplit (line, "\t", 0);
g_free (line);
parts_size = 0;
while (parts[parts_size] != NULL)
parts_size++;
if (parts_size < 2)
return FALSE;
xid = (guint32) atol (parts[1]);
if (g_strcmp0 (parts[0], "open") == 0 && parts_size == 5)
{
name = parts[2];
class = parts[3];
exec = parts[4];
BamfLegacyWindowTest *test_win = bamf_legacy_window_test_new (xid, name, class, exec);
_bamf_legacy_screen_open_test_window (self, test_win);
}
else if (g_strcmp0 (parts[0], "close") == 0 && parts_size == 2)
{
for (l = self->priv->windows; l; l = l->next)
{
window = l->data;
if (bamf_legacy_window_get_xid (window) == xid)
{
_bamf_legacy_screen_close_test_window (self, BAMF_LEGACY_WINDOW_TEST (window));
break;
}
}
}
else if (g_strcmp0 (parts[0], "attention") == 0 && parts_size == 3)
{
gboolean attention = FALSE;
if (g_strcmp0 (parts[2], "true") == 0)
attention = TRUE;
else if (g_strcmp0 (parts[2], "false") == 0)
attention = FALSE;
else
return TRUE;
for (l = self->priv->windows; l; l = l->next)
{
if (bamf_legacy_window_get_xid (l->data) == xid)
{
bamf_legacy_window_test_set_attention (l->data, attention);
break;
}
}
}
else if (g_strcmp0 (parts[0], "skip") == 0 && parts_size == 3)
{
gboolean skip = FALSE;
if (g_strcmp0 (parts[2], "true") == 0)
skip = TRUE;
else if (g_strcmp0 (parts[2], "false") == 0)
skip = FALSE;
else
return TRUE;
for (l = self->priv->windows; l; l = l->next)
{
if (bamf_legacy_window_get_xid (l->data) == xid)
{
bamf_legacy_window_test_set_skip (l->data, skip);
break;
}
}
}
else if (g_strcmp0 (parts[0], "geometry") == 0 && parts_size == 6)
{
int x = atoi (parts[2]);
int y = atoi (parts[3]);
int width = atoi (parts[4]);
int height = atoi (parts[5]);
for (l = self->priv->windows; l; l = l->next)
{
if (bamf_legacy_window_get_xid (l->data) == xid)
{
bamf_legacy_window_test_set_geometry (l->data, x, y, width, height);
break;
}
}
}
else if (g_strcmp0 (parts[0], "maximized") == 0 && parts_size == 3)
{
BamfWindowMaximizationType maximized;
if (g_strcmp0 (parts[2], "maximized") == 0)
maximized = BAMF_WINDOW_MAXIMIZED;
else if (g_strcmp0 (parts[2], "vmaximized") == 0)
maximized = BAMF_WINDOW_VERTICAL_MAXIMIZED;
else if (g_strcmp0 (parts[2], "hmaximized") == 0)
maximized = BAMF_WINDOW_HORIZONTAL_MAXIMIZED;
else if (g_strcmp0 (parts[2], "floating") == 0)
maximized = BAMF_WINDOW_FLOATING;
else
return TRUE;
for (l = self->priv->windows; l; l = l->next)
{
if (bamf_legacy_window_get_xid (l->data) == xid)
{
bamf_legacy_window_test_set_maximized (l->data, maximized);
break;
}
}
}
else
{
g_warning ("Could not parse line\n");
}
g_strfreev (parts);
return TRUE;
}
static gint
compare_windows_by_stack_order (gconstpointer a, gconstpointer b, gpointer data)
{
BamfLegacyScreen *self;
GList *l;
guint xid_a, xid_b;
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (data), 1);
self = BAMF_LEGACY_SCREEN (data);
xid_a = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (a));
xid_b = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (b));
for (l = wnck_screen_get_windows_stacked (self->priv->legacy_screen); l; l = l->next)
{
gulong legacy_xid = wnck_window_get_xid (WNCK_WINDOW (l->data));
if (legacy_xid == xid_a)
return -1;
if (legacy_xid == xid_b)
return 1;
}
return 0;
}
static void
handle_sn_monitor_event (SnMonitorEvent *event,
void *data)
{
BamfLegacyScreen *self = data;
switch (sn_monitor_event_get_type (event))
{
case SN_MONITOR_EVENT_INITIATED:
case SN_MONITOR_EVENT_CHANGED:
{
SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence (event);
const gchar *app_id = sn_startup_sequence_get_application_id (sequence);
g_signal_emit (self, legacy_screen_signals[WINDOW_OPENING], 0, app_id);
}
break;
case SN_MONITOR_EVENT_COMPLETED:
{
SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence (event);
const gchar *app_id = sn_startup_sequence_get_application_id (sequence);
g_signal_emit (self, legacy_screen_signals[WINDOW_OPENING_COMPLETED], 0, app_id);
break;
}
case SN_MONITOR_EVENT_CANCELED:
{
SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence (event);
const gchar *app_id = sn_startup_sequence_get_application_id (sequence);
g_signal_emit (self, legacy_screen_signals[WINDOW_OPENING_CANCELED], 0, app_id);
break;
}
}
}
static void
handle_window_opened (WnckScreen *screen, WnckWindow *window, BamfLegacyScreen *legacy)
{
BamfLegacyWindow *legacy_window;
g_return_if_fail (WNCK_IS_WINDOW (window));
legacy_window = bamf_legacy_window_new (window);
g_signal_connect (G_OBJECT (legacy_window), "closed",
(GCallback) handle_window_closed, legacy);
legacy->priv->windows = g_list_insert_sorted_with_data (legacy->priv->windows, legacy_window,
compare_windows_by_stack_order,
legacy);
g_signal_emit (legacy, legacy_screen_signals[WINDOW_OPENED], 0, legacy_window);
}
static void
handle_stacking_changed (WnckScreen *screen, BamfLegacyScreen *legacy)
{
legacy->priv->windows = g_list_sort_with_data (legacy->priv->windows,
compare_windows_by_stack_order,
legacy);
g_signal_emit (legacy, legacy_screen_signals[STACKING_CHANGED], 0);
}
/* This function allows to push into the screen a window by its xid.
* If the window is already known, it's just ignored, otherwise it gets added
* to the windows list. The BamfLegacyScreen should automatically update its
* windows list when they are added/removed from the screen, but if a child
* BamfLegacyWindow is closed, then it could be possible to re-add it. */
void
bamf_legacy_screen_inject_window (BamfLegacyScreen *self, guint xid)
{
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (self));
BamfLegacyWindow *window;
GList *l;
for (l = self->priv->windows; l; l = l->next)
{
window = l->data;
if (bamf_legacy_window_get_xid (window) == xid)
{
return;
}
}
WnckWindow *legacy_window = wnck_window_get (xid);
if (WNCK_IS_WINDOW (legacy_window))
{
handle_window_opened (NULL, legacy_window, self);
}
}
void
bamf_legacy_screen_set_state_file (BamfLegacyScreen *self,
const char *file)
{
GFile *gfile;
GDataInputStream *stream;
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (self));
// Disconnect our handlers so we can work purely on the file
g_signal_handlers_disconnect_by_func (self->priv->legacy_screen, handle_window_opened, self);
g_signal_handlers_disconnect_by_func (self->priv->legacy_screen, handle_window_closed, self);
g_signal_handlers_disconnect_by_func (self->priv->legacy_screen, handle_stacking_changed, self);
gfile = g_file_new_for_path (file);
if (!file)
{
g_error ("Could not open file %s", file);
}
stream = g_data_input_stream_new (G_INPUT_STREAM (g_file_read (gfile, NULL, NULL)));
if (!stream)
{
g_error ("Could not open file stream for %s", file);
}
self->priv->file = gfile;
self->priv->stream = stream;
g_timeout_add (500, (GSourceFunc) on_state_file_load_timeout, self);
}
GList *
bamf_legacy_screen_get_windows (BamfLegacyScreen *screen)
{
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
return screen->priv->windows;
}
BamfLegacyWindow *
bamf_legacy_screen_get_active_window (BamfLegacyScreen *screen)
{
BamfLegacyWindow *window;
GList *l;
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
for (l = screen->priv->windows; l; l = l->next)
{
window = l->data;
if (bamf_legacy_window_is_active (window))
return window;
}
return NULL;
}
static BamfLegacyWindow *
bamf_legacy_screen_get_window_by_xid (BamfLegacyScreen *screen, Window xid)
{
BamfLegacyWindow *window;
GList *l;
g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
for (l = screen->priv->windows; l; l = l->next)
{
window = l->data;
if (bamf_legacy_window_get_xid (window) == xid)
return window;
}
return NULL;
}
static void
handle_active_window_changed (WnckScreen *screen, WnckWindow *previous, BamfLegacyScreen *self)
{
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (self));
g_signal_emit (self, legacy_screen_signals[ACTIVE_WINDOW_CHANGED], 0);
}
static void
bamf_legacy_screen_finalize (GObject *object)
{
BamfLegacyScreen *self = BAMF_LEGACY_SCREEN (object);
if (self->priv->sn_display)
{
sn_display_unref (self->priv->sn_display);
self->priv->sn_display = NULL;
}
if (self->priv->sn_monitor_context)
{
sn_monitor_context_unref (self->priv->sn_monitor_context);
self->priv->sn_monitor_context = NULL;
}
if (self->priv->windows)
g_list_free_full (self->priv->windows, g_object_unref);
if (self->priv->file)
g_object_unref (self->priv->file);
if (self->priv->stream)
g_object_unref (self->priv->stream);
wnck_shutdown ();
static_screen = NULL;
G_OBJECT_CLASS (bamf_legacy_screen_parent_class)->finalize (object);
}
static void
bamf_legacy_screen_init (BamfLegacyScreen * self)
{
self->priv = BAMF_LEGACY_SCREEN_GET_PRIVATE (self);
}
static void
bamf_legacy_screen_class_init (BamfLegacyScreenClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = bamf_legacy_screen_finalize;
g_type_class_add_private (klass, sizeof (BamfLegacyScreenPrivate));
legacy_screen_signals [WINDOW_OPENING] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, window_opening),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
legacy_screen_signals [WINDOW_OPENING_COMPLETED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_COMPLETED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, window_opening_completed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
legacy_screen_signals [WINDOW_OPENING_CANCELED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENING_CANCELED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, window_opening_canceled),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
legacy_screen_signals [WINDOW_OPENED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_OPENED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, window_opened),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_LEGACY_WINDOW);
legacy_screen_signals [WINDOW_CLOSED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_WINDOW_CLOSED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, window_closed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_LEGACY_WINDOW);
legacy_screen_signals [STACKING_CHANGED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_STACKING_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, stacking_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
legacy_screen_signals [ACTIVE_WINDOW_CHANGED] =
g_signal_new (BAMF_LEGACY_SCREEN_SIGNAL_ACTIVE_WINDOW_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfLegacyScreenClass, active_window_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
#include
GdkFilterReturn filter_compiz_messages(GdkXEvent *gdkxevent, GdkEvent *event, gpointer data)
{
BamfLegacyScreen *self = data;
BamfLegacyWindow *window;
XEvent *xevent = gdkxevent;
if (xevent->type == ClientMessage)
{
if (sn_display_process_event (self->priv->sn_display, xevent))
{
return GDK_FILTER_REMOVE;
}
if (xevent->xclient.message_type == _COMPIZ_TOOLKIT_ACTION)
{
Atom msg = xevent->xclient.data.l[0];
if (msg == _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU)
{
window = bamf_legacy_screen_get_window_by_xid (self, xevent->xany.window);
if (BAMF_IS_LEGACY_WINDOW (window) &&
bamf_legacy_window_get_window_type(window) != BAMF_WINDOW_DESKTOP)
{
Time time = xevent->xclient.data.l[1];
int button = xevent->xclient.data.l[2];
int x = xevent->xclient.data.l[3];
int y = xevent->xclient.data.l[4];
bamf_legacy_window_show_action_menu (window, time, button, x, y);
return GDK_FILTER_REMOVE;
}
}
}
}
return GDK_FILTER_CONTINUE;
}
BamfLegacyScreen *
bamf_legacy_screen_get_default ()
{
BamfLegacyScreen *self;
Display *dpy;
if (static_screen)
return static_screen;
self = (BamfLegacyScreen *) g_object_new (BAMF_TYPE_LEGACY_SCREEN, NULL);
static_screen = self;
if (g_strcmp0 (g_getenv ("BAMF_TEST_MODE"), "TRUE") == 0)
return static_screen;
wnck_set_default_icon_size (BAMF_DEFAULT_ICON_SIZE);
wnck_set_default_mini_icon_size (BAMF_DEFAULT_MINI_ICON_SIZE);
self->priv->legacy_screen = wnck_screen_get_default ();
dpy = gdk_x11_get_default_xdisplay ();
self->priv->sn_display = sn_display_new (dpy, NULL, NULL);
self->priv->sn_monitor_context = sn_monitor_context_new (self->priv->sn_display,
DefaultScreen (dpy),
handle_sn_monitor_event,
self, NULL);
g_signal_connect (G_OBJECT (self->priv->legacy_screen), "window-opened",
(GCallback) handle_window_opened, self);
g_signal_connect (G_OBJECT (self->priv->legacy_screen), "window-stacking-changed",
(GCallback) handle_stacking_changed, self);
g_signal_connect (G_OBJECT (self->priv->legacy_screen), "active-window-changed",
(GCallback) handle_active_window_changed, self);
if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)
{
_COMPIZ_TOOLKIT_ACTION = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION", False);
_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", False);
gdk_window_add_filter (NULL, filter_compiz_messages, self);
}
return static_screen;
}
// Private functions for testing purposes
void _bamf_legacy_screen_open_test_window (BamfLegacyScreen *self, BamfLegacyWindowTest *test_window)
{
GList *l;
BamfLegacyWindow *window;
guint xid;
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (test_window));
window = BAMF_LEGACY_WINDOW (test_window);
xid = bamf_legacy_window_get_xid (window);
for (l = self->priv->windows; l; l = l->next)
{
if (bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (l->data)) == xid)
{
return;
}
}
self->priv->windows = g_list_append (self->priv->windows, window);
g_signal_emit (self, legacy_screen_signals[STACKING_CHANGED], 0);
g_signal_connect (G_OBJECT (window), "closed",
(GCallback) handle_window_closed, self);
g_signal_emit (self, legacy_screen_signals[WINDOW_OPENED], 0, window);
}
void _bamf_legacy_screen_close_test_window (BamfLegacyScreen *self, BamfLegacyWindowTest *test_window)
{
g_return_if_fail (BAMF_IS_LEGACY_SCREEN (self));
g_return_if_fail (BAMF_IS_LEGACY_WINDOW_TEST (test_window));
// This will cause handle_window_closed to be called
bamf_legacy_window_test_close (BAMF_LEGACY_WINDOW_TEST (test_window));
}
./src/bamf-view.c 0000644 0000156 0000165 00000072714 12704153435 013724 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2011 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
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include "bamf-view.h"
#define BAMF_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_VIEW, BamfViewPrivate))
static void bamf_view_dbus_view_iface_init (BamfDBusItemViewIface *iface);
G_DEFINE_TYPE_WITH_CODE (BamfView, bamf_view, BAMF_DBUS_ITEM_TYPE_OBJECT_SKELETON,
G_IMPLEMENT_INTERFACE (BAMF_DBUS_ITEM_TYPE_VIEW,
bamf_view_dbus_view_iface_init));
#define STARTING_MAX_WAIT 15
enum
{
PROP_0,
PROP_NAME,
PROP_ICON,
PROP_ACTIVE,
PROP_STARTING,
PROP_RUNNING,
PROP_URGENT,
PROP_USER_VISIBLE,
};
enum
{
CLOSED_INTERNAL,
EXPORTED,
LAST_SIGNAL,
};
static guint view_signals[LAST_SIGNAL] = { 0 };
typedef struct _BamfViewPropCache
{
/* FIXME: temporary cache these properties until we don't export the view
* to the bus, we need this until the skeleton won't be smart enough to emit
* signals as soon as the object is exported */
gboolean starting;
gboolean running;
gboolean user_visible;
gboolean urgent;
gboolean active;
gchar *name;
gchar *icon;
} BamfViewPropCache;
struct _BamfViewPrivate
{
BamfDBusItemView * dbus_iface;
BamfViewPropCache * props;
char * path;
GList * children;
GList * parents;
gboolean closed;
guint starting_timeout;
/* FIXME: remove this as soon as we move to properties on library as well */
guint active_changed_idle;
};
static gboolean
on_active_changed_idle (gpointer data)
{
g_return_val_if_fail (BAMF_IS_VIEW (data), FALSE);
BamfView *self = BAMF_VIEW (data);
gboolean active = bamf_view_is_active (self);
g_signal_emit_by_name (self, "active-changed", active);
self->priv->active_changed_idle = 0;
return FALSE;
}
static void
bamf_view_active_changed (BamfView *view, gboolean active)
{
g_return_if_fail (BAMF_IS_VIEW (view));
gboolean emit = TRUE;
if (BAMF_VIEW_GET_CLASS (view)->active_changed)
{
emit = !BAMF_VIEW_GET_CLASS (view)->active_changed (view, active);
}
if (emit)
{
if (view->priv->active_changed_idle)
g_source_remove (view->priv->active_changed_idle);
guint idle = g_idle_add_full (G_PRIORITY_DEFAULT, on_active_changed_idle, view, NULL);
view->priv->active_changed_idle = idle;
}
}
static void
bamf_view_name_changed (BamfView *view, const gchar *new_name)
{
g_return_if_fail (BAMF_IS_VIEW (view));
const gchar *old_name = bamf_view_get_name (view);
g_signal_emit_by_name (view, "name-changed", old_name, new_name);
}
static void
bamf_view_icon_changed (BamfView *view, const gchar *new_icon)
{
g_object_notify (G_OBJECT (view), "icon");
}
static void
bamf_view_user_visible_changed (BamfView *view, gboolean user_visible)
{
g_return_if_fail (BAMF_IS_VIEW (view));
gboolean emit = TRUE;
if (BAMF_VIEW_GET_CLASS (view)->user_visible_changed)
{
emit = !BAMF_VIEW_GET_CLASS (view)->user_visible_changed (view, user_visible);
}
if (emit)
g_signal_emit_by_name (view, "user-visible-changed", user_visible);
}
static gboolean
on_starting_timeout (gpointer data)
{
BamfView *view = data;
bamf_view_set_starting (view, FALSE);
view->priv->starting_timeout = 0;
return FALSE;
}
static void
bamf_view_starting_changed (BamfView *view, gboolean starting)
{
BamfViewPrivate *priv;
g_return_if_fail (BAMF_IS_VIEW (view));
priv = view->priv;
if (BAMF_VIEW_GET_CLASS (view)->starting_changed)
{
BAMF_VIEW_GET_CLASS (view)->starting_changed (view, starting);
}
if (priv->starting_timeout)
{
g_source_remove (priv->starting_timeout);
priv->starting_timeout = 0;
}
if (starting)
priv->starting_timeout = g_timeout_add_seconds (STARTING_MAX_WAIT, on_starting_timeout, view);
}
static void
bamf_view_running_changed (BamfView *view, gboolean running)
{
g_return_if_fail (BAMF_IS_VIEW (view));
gboolean emit = TRUE;
if (BAMF_VIEW_GET_CLASS (view)->running_changed)
{
emit = !BAMF_VIEW_GET_CLASS (view)->running_changed (view, running);
}
if (emit)
g_signal_emit_by_name (view, "running-changed", running);
if (running)
bamf_view_set_starting (view, FALSE);
}
static void
bamf_view_urgent_changed (BamfView *view, gboolean urgent)
{
g_return_if_fail (BAMF_IS_VIEW (view));
gboolean emit = TRUE;
if (BAMF_VIEW_GET_CLASS (view)->urgent_changed)
{
emit = !BAMF_VIEW_GET_CLASS (view)->urgent_changed (view, urgent);
}
if (emit)
g_signal_emit_by_name (view, "urgent-changed", urgent);
}
void
bamf_view_close (BamfView *view)
{
BamfViewPrivate *priv;
gboolean emit = TRUE;
GList *l;
g_return_if_fail (BAMF_IS_VIEW (view));
priv = view->priv;
if (priv->closed)
return;
priv->closed = TRUE;
if (BAMF_VIEW_GET_CLASS (view)->closed)
{
emit = !BAMF_VIEW_GET_CLASS (view)->closed (view);
}
if (priv->children)
{
for (l = priv->children; l; l = l->next)
{
if (BAMF_IS_VIEW (l->data))
bamf_view_remove_child (view, l->data);
}
g_list_free (priv->children);
priv->children = NULL;
}
if (emit)
{
g_object_ref (view);
g_signal_emit (view, view_signals[CLOSED_INTERNAL], 0);
g_signal_emit_by_name (view, "closed");
g_object_unref (view);
}
}
const char *
bamf_view_get_path (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
return view->priv->path;
}
GVariant *
bamf_view_get_children_paths (BamfView *view)
{
GVariantBuilder b;
GList *l;
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
for (l = view->priv->children; l; l = l->next)
{
BamfView *child = l->data;
const char *path = bamf_view_get_path (child);
if (!path)
continue;
g_variant_builder_add (&b, "s", path);
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GList *
bamf_view_get_children (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
return view->priv->children;
}
GVariant *
bamf_view_get_parent_paths (BamfView *view)
{
GVariantBuilder b;
GList *l;
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
g_variant_builder_init (&b, G_VARIANT_TYPE ("(as)"));
g_variant_builder_open (&b, G_VARIANT_TYPE ("as"));
for (l = view->priv->parents; l; l = l->next)
{
BamfView *parent = l->data;
const char *path = bamf_view_get_path (parent);
if (!path)
continue;
g_variant_builder_add (&b, "s", path);
}
g_variant_builder_close (&b);
return g_variant_builder_end (&b);
}
GList *
bamf_view_get_parents (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
return view->priv->parents;
}
static void
bamf_view_handle_child_closed (BamfView *child,
BamfView *view)
{
bamf_view_remove_child (view, child);
}
static void
on_child_view_exported (BamfView *child, BamfView *view)
{
g_signal_emit_by_name (view, "child-added", bamf_view_get_path (child));
g_signal_handlers_disconnect_by_func (child, on_child_view_exported, view);
}
void
bamf_view_add_child (BamfView *view,
BamfView *child)
{
const char * added;
g_return_if_fail (BAMF_IS_VIEW (view));
g_return_if_fail (BAMF_IS_VIEW (child));
g_signal_connect (G_OBJECT (child), "closed-internal",
G_CALLBACK (bamf_view_handle_child_closed), view);
/* Make sure our parent child lists are ok, pay attention to whose list you add parents to */
view->priv->children = g_list_prepend (view->priv->children, child);
child->priv->parents = g_list_prepend (child->priv->parents, view);
if (bamf_view_is_on_bus (child))
{
added = bamf_view_get_path (child);
g_signal_emit_by_name (view, "child-added", added);
}
else
{
g_signal_connect (G_OBJECT (child), "exported",
G_CALLBACK (on_child_view_exported), view);
}
// Do this by hand so we can pass and object instead of a string
if (BAMF_VIEW_GET_CLASS (view)->child_added)
BAMF_VIEW_GET_CLASS (view)->child_added (view, child);
}
void
bamf_view_remove_child (BamfView *view, BamfView *child)
{
const char *removed;
g_return_if_fail (BAMF_IS_VIEW (view));
g_return_if_fail (BAMF_IS_VIEW (child));
g_signal_handlers_disconnect_by_data (child, view);
/* Make sure our parent child lists are ok, pay attention to whose list you add parents to */
view->priv->children = g_list_remove (view->priv->children, child);
child->priv->parents = g_list_remove (child->priv->parents, view);
removed = bamf_view_get_path (child);
g_signal_emit_by_name (view, "child-removed", removed);
/* Do this by hand so we can pass and object instead of a string */
if (BAMF_VIEW_GET_CLASS (view)->child_removed)
BAMF_VIEW_GET_CLASS (view)->child_removed (view, child);
}
#define BAMF_VIEW_GET_PROPERTY(v, property, ret_val) \
g_return_val_if_fail (BAMF_IS_VIEW (v), ret_val); \
\
if (v->priv->props) \
return v->priv->props->property; \
\
return _bamf_dbus_item_view_get_##property (v->priv->dbus_iface);
#define BAMF_VIEW_SET_BOOL_PROPERTY(v, property) \
g_return_if_fail (BAMF_IS_VIEW (v)); \
\
if (property == bamf_view_is_##property (v)) \
return; \
\
if (v->priv->props) \
{ \
v->priv->props->property = property; \
} \
else \
{ \
_bamf_dbus_item_view_set_##property (v->priv->dbus_iface, property); \
} \
\
bamf_view_##property##_changed (v, property);
#define BAMF_VIEW_SET_STRING_PROPERTY(v, property) \
g_return_if_fail (BAMF_IS_VIEW (v)); \
\
const gchar *current_value = bamf_view_get_##property (v); \
\
if (current_value == property || g_strcmp0 (current_value, property) == 0) \
return; \
\
bamf_view_##property##_changed (v, property); \
\
if (v->priv->props) \
{ \
g_free (v->priv->props->property); \
v->priv->props->property = g_strdup (property); \
} \
else \
{ \
_bamf_dbus_item_view_set_##property (v->priv->dbus_iface, property); \
}
gboolean
bamf_view_is_active (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, active, FALSE);
}
void
bamf_view_set_active (BamfView *view,
gboolean active)
{
BAMF_VIEW_SET_BOOL_PROPERTY (view, active);
}
gboolean
bamf_view_is_urgent (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, urgent, FALSE);
}
void
bamf_view_set_urgent (BamfView *view,
gboolean urgent)
{
BAMF_VIEW_SET_BOOL_PROPERTY (view, urgent);
}
gboolean
bamf_view_is_starting (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, starting, FALSE);
}
void
bamf_view_set_starting (BamfView *view,
gboolean starting)
{
BAMF_VIEW_SET_BOOL_PROPERTY (view, starting);
}
gboolean
bamf_view_is_running (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, running, FALSE);
}
void
bamf_view_set_running (BamfView *view,
gboolean running)
{
BAMF_VIEW_SET_BOOL_PROPERTY (view, running);
}
gboolean
bamf_view_is_user_visible (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, user_visible, FALSE);
}
void
bamf_view_set_user_visible (BamfView *view, gboolean user_visible)
{
BAMF_VIEW_SET_BOOL_PROPERTY (view, user_visible);
}
const char *
bamf_view_get_icon (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, icon, NULL);
}
void
bamf_view_set_icon (BamfView *view, const char *icon)
{
BAMF_VIEW_SET_STRING_PROPERTY (view, icon);
}
const char *
bamf_view_get_name (BamfView *view)
{
BAMF_VIEW_GET_PROPERTY (view, name, NULL);
}
void
bamf_view_set_name (BamfView *view, const char *name)
{
BAMF_VIEW_SET_STRING_PROPERTY (view, name);
}
const char *
bamf_view_get_view_type (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
if (BAMF_VIEW_GET_CLASS (view)->view_type)
return BAMF_VIEW_GET_CLASS (view)->view_type (view);
return "view";
}
static char *
bamf_view_get_stable_bus_name (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
if (BAMF_VIEW_GET_CLASS (view)->stable_bus_name)
return BAMF_VIEW_GET_CLASS (view)->stable_bus_name (view);
return g_strdup_printf ("view/%p", view);
}
static void
bamf_view_cached_properties_clear (BamfView *view)
{
if (!view->priv->props)
return;
g_free (view->priv->props->name);
g_free (view->priv->props->icon);
g_free (view->priv->props);
view->priv->props = NULL;
}
static void
bamf_view_cached_properties_notify (BamfView *view)
{
if (!view->priv->props || !bamf_view_is_on_bus (view))
return;
/* Temporary disable the cache so that cached values will be set on the skeleton */
BamfViewPropCache *cache = view->priv->props;
view->priv->props = NULL;
bamf_view_set_name (view, cache->name);
bamf_view_set_icon (view, cache->icon);
bamf_view_set_active (view, cache->active);
bamf_view_set_starting (view, cache->starting);
bamf_view_set_running (view, cache->running);
bamf_view_set_user_visible (view, cache->user_visible);
bamf_view_set_urgent (view, cache->urgent);
view->priv->props = cache;
}
const char *
bamf_view_export_on_bus (BamfView *view, GDBusConnection *connection)
{
char *path = NULL;
GList *ifaces, *l;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
if (!view->priv->path)
{
gboolean exported = TRUE;
char *stable_name = bamf_view_get_stable_bus_name (view);
path = g_strconcat (BAMF_DBUS_BASE_PATH, "/", stable_name, NULL);
g_free (stable_name);
BAMF_VIEW_GET_CLASS (view)->names = g_list_prepend (BAMF_VIEW_GET_CLASS (view)->names, path);
view->priv->path = path;
ifaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (view));
/* The dbus object interface list is in reversed order, we try to export
* the interfaces in bottom to top order (BamfView should be the first) */
for (l = g_list_last (ifaces); l; l = l->prev)
{
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (l->data),
connection, path, &error);
if (error)
{
g_critical ("Can't register BAMF view interface: %s", error->message);
g_clear_error (&error);
exported = FALSE;
}
}
if (exported)
{
/* FIXME: if we change the properties before that the view has been
* exported, the skeleton doesn't emit the proper signals to notify
* the proxy that the values have been changed, and this causes
* the properties not to be updated on the client side.
* So we store the values locally until the proxy is not exported,
* then we notify our clients. */
bamf_view_cached_properties_notify (view);
bamf_view_cached_properties_clear (view);
g_signal_emit (view, view_signals[EXPORTED], 0);
}
g_list_free_full (ifaces, g_object_unref);
}
return view->priv->path;
}
gboolean
bamf_view_is_on_bus (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
GDBusInterfaceSkeleton *dbus_iface;
const gchar *exported_path;
if (!view->priv->path)
return FALSE;
dbus_iface = G_DBUS_INTERFACE_SKELETON (view->priv->dbus_iface);
exported_path = g_dbus_interface_skeleton_get_object_path (dbus_iface);
return (exported_path != NULL);
}
static void
on_view_active_changed (BamfView *view, gboolean active, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "active-changed", active);
}
static void
on_view_running_changed (BamfView *view, gboolean running, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "running-changed", running);
}
static void
on_view_urgent_changed (BamfView *view, gboolean urgent, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "urgent-changed", urgent);
}
static void
on_view_user_visible_changed (BamfView *view, gboolean user_visible, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "user-visible-changed", user_visible);
}
static void
on_view_name_changed (BamfView *view, const gchar *old_name, const gchar *new_name, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "name-changed",
old_name ? old_name : "", new_name ? new_name : "");
}
static void
on_view_child_added (BamfView *view, const gchar *child_path, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "child-added",
child_path ? child_path : "");
}
static void
on_view_child_removed (BamfView *view, const gchar *child_path, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_signal_emit_by_name (view->priv->dbus_iface, "child-removed",
child_path ? child_path : "");
}
static void
on_view_closed (BamfView *view, gpointer _not_used)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_dbus_object_skeleton_flush (G_DBUS_OBJECT_SKELETON (view));
g_signal_emit_by_name (view->priv->dbus_iface, "closed");
}
static gboolean
on_dbus_handle_view_type (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
const char *type = bamf_view_get_view_type (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", type));
return TRUE;
}
static gboolean
on_dbus_handle_user_visible (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
gboolean user_visible = bamf_view_is_user_visible (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", user_visible));
return TRUE;
}
static gboolean
on_dbus_handle_icon (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
const char *icon = bamf_view_get_icon (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", icon ? icon : ""));
return TRUE;
}
static gboolean
on_dbus_handle_name (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
const char *name = bamf_view_get_name (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", name ? name : ""));
return TRUE;
}
static gboolean
on_dbus_handle_is_urgent (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
gboolean is_urgent = bamf_view_is_urgent (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", is_urgent));
return TRUE;
}
static gboolean
on_dbus_handle_is_running (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
gboolean is_running = bamf_view_is_running (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", is_running));
return TRUE;
}
static gboolean
on_dbus_handle_is_active (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
gboolean is_active = bamf_view_is_active (view);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(b)", is_active));
return TRUE;
}
static gboolean
on_dbus_handle_parents (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
GVariant *parents = bamf_view_get_parent_paths (view);
g_dbus_method_invocation_return_value (invocation, parents);
return TRUE;
}
static gboolean
on_dbus_handle_children (BamfDBusItemView *interface,
GDBusMethodInvocation *invocation,
BamfView *view)
{
GVariant *children = bamf_view_get_children_paths (view);
g_dbus_method_invocation_return_value (invocation, children);
return TRUE;
}
static void
bamf_view_dispose (GObject *object)
{
BamfView *view = BAMF_VIEW (object);
BamfViewPrivate *priv = view->priv;
if (priv->path)
{
g_free (priv->path);
priv->path = NULL;
}
if (priv->children)
{
g_list_free (priv->children);
priv->children = NULL;
}
if (priv->parents)
{
g_list_free (priv->parents);
priv->parents = NULL;
}
if (priv->starting_timeout)
{
g_source_remove (priv->starting_timeout);
priv->starting_timeout = 0;
}
if (priv->active_changed_idle)
{
g_source_remove (priv->active_changed_idle);
priv->active_changed_idle = 0;
}
bamf_view_cached_properties_clear (view);
g_dbus_object_skeleton_flush (G_DBUS_OBJECT_SKELETON (view));
G_OBJECT_CLASS (bamf_view_parent_class)->dispose (object);
}
static void
bamf_view_finalize (GObject *object)
{
BamfView *view = BAMF_VIEW (object);
g_object_unref (view->priv->dbus_iface);
G_OBJECT_CLASS (bamf_view_parent_class)->finalize (object);
}
static void
bamf_view_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
BamfView *view = BAMF_VIEW (object);
switch (property_id)
{
case PROP_NAME:
g_value_set_string (value, bamf_view_get_name (view));
break;
case PROP_ICON:
g_value_set_string (value, bamf_view_get_icon (view));
break;
case PROP_ACTIVE:
g_value_set_boolean (value, bamf_view_is_active (view));
break;
case PROP_URGENT:
g_value_set_boolean (value, bamf_view_is_urgent (view));
break;
case PROP_USER_VISIBLE:
g_value_set_boolean (value, bamf_view_is_user_visible (view));
break;
case PROP_STARTING:
g_value_set_boolean (value, bamf_view_is_starting (view));
break;
case PROP_RUNNING:
g_value_set_boolean (value, bamf_view_is_running (view));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
bamf_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
bamf_view_init (BamfView * self)
{
self->priv = BAMF_VIEW_GET_PRIVATE (self);
/* Initializing the dbus interface */
self->priv->dbus_iface = _bamf_dbus_item_view_skeleton_new ();
self->priv->props = g_new0 (BamfViewPropCache, 1);
/* We need to connect to the object own signals to redirect them to the dbus
* interface */
g_signal_connect (self, "active-changed", G_CALLBACK (on_view_active_changed), NULL);
g_signal_connect (self, "running-changed", G_CALLBACK (on_view_running_changed), NULL);
g_signal_connect (self, "urgent-changed", G_CALLBACK (on_view_urgent_changed), NULL);
g_signal_connect (self, "user-visible-changed", G_CALLBACK (on_view_user_visible_changed), NULL);
g_signal_connect (self, "name-changed", G_CALLBACK (on_view_name_changed), NULL);
g_signal_connect (self, "child-added", G_CALLBACK (on_view_child_added), NULL);
g_signal_connect (self, "child-removed", G_CALLBACK (on_view_child_removed), NULL);
g_signal_connect (self, "closed", G_CALLBACK (on_view_closed), NULL);
/* Registering signal callbacks to reply to dbus method calls */
g_signal_connect (self->priv->dbus_iface, "handle-view-type",
G_CALLBACK (on_dbus_handle_view_type), self);
g_signal_connect (self->priv->dbus_iface, "handle-user-visible",
G_CALLBACK (on_dbus_handle_user_visible), self);
g_signal_connect (self->priv->dbus_iface, "handle-icon",
G_CALLBACK (on_dbus_handle_icon), self);
g_signal_connect (self->priv->dbus_iface, "handle-name",
G_CALLBACK (on_dbus_handle_name), self);
g_signal_connect (self->priv->dbus_iface, "handle-is-urgent",
G_CALLBACK (on_dbus_handle_is_urgent), self);
g_signal_connect (self->priv->dbus_iface, "handle-is-running",
G_CALLBACK (on_dbus_handle_is_running), self);
g_signal_connect (self->priv->dbus_iface, "handle-is-active",
G_CALLBACK (on_dbus_handle_is_active), self);
g_signal_connect (self->priv->dbus_iface, "handle-parents",
G_CALLBACK (on_dbus_handle_parents), self);
g_signal_connect (self->priv->dbus_iface, "handle-children",
G_CALLBACK (on_dbus_handle_children), self);
/* Setting the interface for the dbus object */
_bamf_dbus_item_object_skeleton_set_view (BAMF_DBUS_ITEM_OBJECT_SKELETON (self),
self->priv->dbus_iface);
}
static void
bamf_view_dbus_view_iface_init (BamfDBusItemViewIface *iface)
{
}
static void
bamf_view_class_init (BamfViewClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = bamf_view_dispose;
object_class->finalize = bamf_view_finalize;
object_class->get_property = bamf_view_get_property;
object_class->set_property = bamf_view_set_property;
g_type_class_add_private (klass, sizeof (BamfViewPrivate));
/* Overriding the properties defined in the interface, this is needed
* but we actually don't use these properties, as we act like a proxy */
g_object_class_override_property (object_class, PROP_NAME, "name");
g_object_class_override_property (object_class, PROP_ICON, "icon");
g_object_class_override_property (object_class, PROP_ACTIVE, "active");
g_object_class_override_property (object_class, PROP_URGENT, "urgent");
g_object_class_override_property (object_class, PROP_STARTING, "starting");
g_object_class_override_property (object_class, PROP_RUNNING, "running");
g_object_class_override_property (object_class, PROP_USER_VISIBLE, "user-visible");
view_signals [CLOSED_INTERNAL] =
g_signal_new ("closed-internal",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BamfViewClass, closed_internal),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
view_signals [EXPORTED] =
g_signal_new ("exported",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, exported),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
./README 0000644 0000156 0000165 00000000000 12704153435 011747 0 ustar jenkins jenkins ./Makefile.am 0000644 0000156 0000165 00000000433 12704153435 013135 0 ustar jenkins jenkins ACLOCAL_AMFLAGS = -I m4
include $(top_srcdir)/Makefile.am.coverage
SUBDIRS = \
lib/libbamf-private \
lib/libbamf \
src \
tests \
data \
doc
EXTRA_DIST = COPYING.LGPL autogen.sh build.rules.mk
DISTCHECK_CONFIGURE_FLAGS = --enable-introspection=no --enable-gtk-doc=yes
./COPYING 0000644 0000156 0000165 00000104513 12704153435 012140 0 ustar jenkins jenkins GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
./AUTHORS 0000644 0000156 0000165 00000000000 12704153435 012137 0 ustar jenkins jenkins ./build.rules.mk 0000644 0000156 0000165 00000006114 12704153435 013664 0 ustar jenkins jenkins # Rules to more easily specify a C# build for automake.
#
# Inspired and adapted from Banshee and GNOME Do's build systems
SOURCES_BUILD = $(addprefix $(srcdir)/, $(FILES))
RESOURCES_EXPANDED = $(addprefix $(srcdir)/, $(RESOURCES))
RESOURCES_BUILD = $(foreach resource, $(RESOURCES_EXPANDED), \
-resource:$(resource),$(notdir $(resource)))
BUILD_DIR = $(top_builddir)/build
ASSEMBLY_EXTENSION = $(strip $(patsubst library, dll, $(TARGET)))
ASSEMBLY_FILE = $(BUILD_DIR)/$(ASSEMBLY).$(ASSEMBLY_EXTENSION)
STD_REFERENCES = $(foreach ref,$(filter-out -r:%,$(REFERENCES)),-r:$(ref))
BUILD_REFERENCES = $(filter -r:%,$(REFERENCES) $(STD_REFERENCES))
COMPONENT_REFERENCES = $(foreach ref, $(PROJECT_REFERENCES),-r:$(BUILD_DIR)/$(ref).dll)
COMPONENT_DEPS = $(foreach ref,$(PROJECT_REFERENCES),$(BUILD_DIR)/$(ref).dll)
OUTPUT_FILES = \
$(ASSEMBLY_FILE)
moduledir = $(pkglibdir)
# Install libraries as data; there's no need for them to be excutable
module_DATA = $(foreach file,$(filter %.dll,$(OUTPUT_FILES)),$(file) $(file).mdb) $(foreach file,$(filter %.exe,$(OUTPUT_FILES)),$(file).mdb)
# Install executables as scripts
module_SCRIPTS = $(filter %.exe,$(OUTPUT_FILES))
MCS_FLAGS = $(MCS_LINQ_FLAG) -noconfig -codepage:utf8 -warn:4 -debug
all: $(ASSEMBLY_FILE)
$(ASSEMBLY_FILE).mdb: $(ASSEMBLY_FILE)
build-debug :
@echo $(COMPONENT_REFERENCES)
$(ASSEMBLY_FILE): $(SOURCES_BUILD) $(RESOURCES_EXPANDED) $(COMPONENT_DEPS)
@mkdir -p $(BUILD_DIR)
@colors=no; \
case $$TERM in \
"xterm" | "rxvt" | "rxvt-unicode") \
test "x$$COLORTERM" != "x" && colors=yes ;; \
"xterm-color") colors=yes ;; \
esac; \
if [ "x$$colors" = "xyes" ]; then \
tty -s && true || { colors=no; true; } \
fi; \
test "x$$colors" = "xyes" && \
echo -e "\033[1mCompiling $(notdir $@)...\033[0m" || \
echo "Compiling $(notdir $@)...";
@$(MCS) $(MCS_FLAGS) -target:$(TARGET) -out:$@ $(BUILD_DEFINES) $(BUILD_REFERENCES) $(COMPONENT_REFERENCES) $(RESOURCES_BUILD) $(SOURCES_BUILD)
@if [ -e $(srcdir)/$(notdir $@.config) ]; then \
cp $(srcdir)/$(notdir $@.config) $(BUILD_DIR) ; \
fi;
#
# pkg-config handling
#
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = $(PKG_CONFIG_FILES)
%.pc : %.pc.in
@colors=no; \
case $$TERM in \
"xterm" | "rxvt" | "rxvt-unicode") \
test "x$$COLORTERM" != "x" && colors=yes ;; \
"xterm-color") colors=yes ;; \
esac; \
if [ "x$$colors" = "xyes" ]; then \
tty -s && true || { colors=no; true; } \
fi; \
test "x$$colors" = "xyes" && \
echo -e "\033[1mGenerating $(notdir $@)...\033[0m" || \
echo "Generating $(notdir $@)...";
@sed "s,\@ABI_VERSION\@,$(ABI_VERSION),g; s,\@expanded_libdir\@,$(expanded_libdir),g; s,\@PACKAGE\@,$(PACKAGE),g" < $< > $@
#
# Clean and dist targets
#
EXTRA_DIST = $(SOURCES_BUILD) $(RESOURCES_EXPANDED) $(THEME_ICONS_SOURCE) \
$(foreach pkgcfg_file, $(PKG_CONFIG_FILES), $(pkgcfg_file).in)
CLEANFILES = $(OUTPUT_FILES) $(pkgconfig_DATA)
DISTCLEANFILES = *.pidb
MAINTAINERCLEANFILES = Makefile.in
./m4/ 0000755 0000156 0000165 00000000000 12704153435 011421 5 ustar jenkins jenkins ./m4/gcov.m4 0000644 0000156 0000165 00000005026 12704153435 012624 0 ustar jenkins jenkins # Checks for existence of coverage tools:
# * gcov
# * lcov
# * genhtml
# * gcovr
#
# Sets ac_cv_check_gcov to yes if tooling is present
# and reports the executables to the variables LCOV, GCOVR and GENHTML.
AC_DEFUN([AC_TDD_GCOV],
[
AC_ARG_ENABLE(gcov,
AS_HELP_STRING([--enable-gcov],
[enable coverage testing with gcov]),
[use_gcov=$enableval], [use_gcov=no])
AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
if test "x$use_gcov" = "xyes"; then
# we need gcc:
if test "$GCC" != "yes"; then
AC_MSG_ERROR([GCC is required for --enable-gcov])
fi
# Check if ccache is being used
AC_CHECK_PROG(SHTOOL, shtool, shtool)
if test "$SHTOOL"; then
AS_CASE([`$SHTOOL path $CC`],
[*ccache*], [gcc_ccache=yes],
[gcc_ccache=no])
fi
if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
fi
lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11 1.12"
AC_CHECK_PROG(LCOV, lcov, lcov)
AC_CHECK_PROG(GENHTML, genhtml, genhtml)
if test "$LCOV"; then
AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
glib_cv_lcov_version=invalid
lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
for lcov_check_version in $lcov_version_list; do
if test "$lcov_version" = "$lcov_check_version"; then
glib_cv_lcov_version="$lcov_check_version (ok)"
fi
done
])
else
lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
AC_MSG_ERROR([$lcov_msg])
fi
case $glib_cv_lcov_version in
""|invalid[)]
lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
AC_MSG_ERROR([$lcov_msg])
LCOV="exit 0;"
;;
esac
if test -z "$GENHTML"; then
AC_MSG_ERROR([Could not find genhtml from the lcov package])
fi
ac_cv_check_gcov=yes
ac_cv_check_lcov=yes
# Remove all optimization flags from CFLAGS
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
changequote([,])
# Add the special gcc flags
COVERAGE_CFLAGS="-O0 --coverage"
COVERAGE_CXXFLAGS="-O0 --coverage"
COVERAGE_LDFLAGS="-lgcov"
# Check availability of gcovr
AC_CHECK_PROG(GCOVR, gcovr, gcovr)
if test -z "$GCOVR"; then
ac_cv_check_gcovr=no
else
ac_cv_check_gcovr=yes
fi
fi
]) # AC_TDD_GCOV
./TODO 0000644 0000156 0000165 00000000156 12704153435 011573 0 ustar jenkins jenkins bamfdaemon should recreate the registered_pids database on restart by inspecting the state of libwnck windows
./data/ 0000755 0000156 0000165 00000000000 12704153435 012012 5 ustar jenkins jenkins ./data/Makefile.am 0000644 0000156 0000165 00000001453 12704153435 014051 0 ustar jenkins jenkins servicedir = @datarootdir@/dbus-1/services
service_DATA = org.ayatana.bamf.service
upstartdir = @datarootdir@/upstart/sessions
upstart_DATA = bamfdaemon.conf
bamfdaemondbusrunnerdir = $(pkglibexecdir)
bamfdaemondbusrunner_SCRIPTS = bamfdaemon-dbus-runner
org.ayatana.bamf.service: org.ayatana.bamf.service.in
$(AM_V_GEN)sed "s,@PKGLIBEXECDIR@,$(pkglibexecdir)," $< > $@
bamfdaemon.conf: bamfdaemon.conf.in
$(AM_V_GEN)sed "s,@PKGLIBEXECDIR@,$(pkglibexecdir)," $< > $@
bamfdaemon-dbus-runner: bamfdaemon-dbus-runner.in
$(AM_V_GEN)sed "s,@PKGLIBEXECDIR@,$(pkglibexecdir)," $< > $@
EXTRA_DIST = org.ayatana.bamf.service.in \
bamfdaemon.conf.in \
bamfdaemon-dbus-runner.in
CLEANFILES = org.ayatana.bamf.service \
bamfdaemon.conf \
bamfdaemon-dbus-runner
./data/org.ayatana.bamf.service.in 0000644 0000156 0000165 00000000122 12704153435 017104 0 ustar jenkins jenkins [D-BUS Service]
Name=org.ayatana.bamf
Exec=@PKGLIBEXECDIR@/bamfdaemon-dbus-runner
./data/bamfdaemon-dbus-runner.in 0000644 0000156 0000165 00000000166 12704153435 016700 0 ustar jenkins jenkins #!/bin/bash
if [ -n "$UPSTART_SESSION" ]; then
/sbin/initctl start bamfdaemon
else
@PKGLIBEXECDIR@/bamfdaemon
fi
./data/bamfdaemon.conf.in 0000644 0000156 0000165 00000000446 12704153435 015363 0 ustar jenkins jenkins description "BAMF Application Matcher Framework"
author "Marco Trevisan "
start on (starting hud or starting unity-panel-service or starting unity7)
stop on (stopped hud and stopped unity-panel-service and stopped unity7)
respawn
exec @PKGLIBEXECDIR@/bamfdaemon
./lib/ 0000755 0000156 0000165 00000000000 12704153435 011647 5 ustar jenkins jenkins ./lib/libbamf/ 0000755 0000156 0000165 00000000000 12704153435 013243 5 ustar jenkins jenkins ./lib/libbamf/bamf-matcher.c 0000644 0000156 0000165 00000064021 12704153435 015740 0 ustar jenkins jenkins /*
* Copyright 2010-2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
/**
* SECTION:bamf-matcher
* @short_description: The base class for all matchers
*
* #BamfMatcher is the base class that all matchers need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-matcher.h"
#include "bamf-tab.h"
#include "bamf-view.h"
#include "bamf-view-private.h"
#include "bamf-factory.h"
G_DEFINE_TYPE (BamfMatcher, bamf_matcher, G_TYPE_OBJECT);
#define BAMF_MATCHER_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_MATCHER, BamfMatcherPrivate))
enum
{
VIEW_OPENED,
VIEW_CLOSED,
ACTIVE_APPLICATION_CHANGED,
ACTIVE_WINDOW_CHANGED,
STACKING_ORDER_CHANGED,
LAST_SIGNAL,
};
static guint matcher_signals[LAST_SIGNAL] = { 0 };
struct _BamfMatcherPrivate
{
BamfDBusMatcher *proxy;
GCancellable *cancellable;
BamfWindow *active_window;
BamfApplication *active_application;
};
static BamfMatcher * default_matcher = NULL;
static void bamf_matcher_dispose (GObject *object);
static void
bamf_matcher_finalize (GObject *object)
{
default_matcher = NULL;
g_object_unref (_bamf_factory_get_default ());
G_OBJECT_CLASS (bamf_matcher_parent_class)->finalize (object);
}
static void
bamf_matcher_class_init (BamfMatcherClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (obj_class, sizeof (BamfMatcherPrivate));
obj_class->dispose = bamf_matcher_dispose;
obj_class->finalize = bamf_matcher_finalize;
matcher_signals [VIEW_OPENED] =
g_signal_new (BAMF_MATCHER_SIGNAL_VIEW_OPENED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_VIEW);
matcher_signals [VIEW_CLOSED] =
g_signal_new (BAMF_MATCHER_SIGNAL_VIEW_CLOSED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_VIEW);
matcher_signals [ACTIVE_APPLICATION_CHANGED] =
g_signal_new (BAMF_MATCHER_SIGNAL_ACTIVE_APPLICATION_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 2,
BAMF_TYPE_APPLICATION, BAMF_TYPE_APPLICATION);
matcher_signals [ACTIVE_WINDOW_CHANGED] =
g_signal_new (BAMF_MATCHER_SIGNAL_ACTIVE_WINDOW_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 2,
BAMF_TYPE_WINDOW, BAMF_TYPE_WINDOW);
matcher_signals [STACKING_ORDER_CHANGED] =
g_signal_new (BAMF_MATCHER_SIGNAL_STACKING_ORDER_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static gboolean
track_ptr (GType wanted_type,
BamfView *active,
gpointer *cache_pointer)
{
if (G_TYPE_CHECK_INSTANCE_TYPE (active, wanted_type))
{
if (*cache_pointer == active)
return FALSE;
*cache_pointer = active;
g_object_add_weak_pointer (G_OBJECT (active), cache_pointer);
return TRUE;
}
else if (G_TYPE_CHECK_INSTANCE_TYPE (*cache_pointer, wanted_type))
{
g_object_remove_weak_pointer (G_OBJECT (*cache_pointer), cache_pointer);
*cache_pointer = NULL;
return TRUE;
}
return FALSE;
}
static void
bamf_matcher_on_name_owner_changed (BamfDBusMatcher *proxy,
GParamSpec *param,
BamfMatcher *matcher)
{
/* This is called when the bamfdaemon is killed / started */
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
if (!name_owner)
{
track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &matcher->priv->active_application);
track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &matcher->priv->active_window);
}
g_free (name_owner);
}
static void
bamf_matcher_on_view_opened (BamfDBusMatcher *proxy,
const char *path,
const char *type,
BamfMatcher *matcher)
{
BamfView *view;
BamfFactory *factory = _bamf_factory_get_default ();
view = _bamf_factory_view_for_path_type_str (factory, path, type);
if (!BAMF_IS_VIEW (view))
return;
/* We manually set the view as not closed, to avoid issues like bug #925421 */
_bamf_view_set_closed (view, FALSE);
g_signal_emit (matcher, matcher_signals[VIEW_OPENED], 0, view);
}
static void
bamf_matcher_on_view_closed (BamfDBusMatcher *proxy,
const char *path,
const char *type,
BamfMatcher *matcher)
{
BamfView *view;
BamfFactory *factory = _bamf_factory_get_default ();
view = _bamf_factory_view_for_path_type_str (factory, path, type);
if (!BAMF_IS_VIEW (view))
return;
/* We manually set the view as closed, to avoid issues like bug #925421 */
_bamf_view_set_closed (view, TRUE);
g_signal_emit (matcher, matcher_signals[VIEW_CLOSED], 0, view);
}
static void
bamf_matcher_on_active_application_changed (BamfDBusMatcher *proxy,
const char *old_path,
const char *new_path,
BamfMatcher *matcher)
{
BamfView *old_view;
BamfView *new_view;
BamfFactory *factory;
factory = _bamf_factory_get_default ();
old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_APPLICATION);
new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_APPLICATION);
if (track_ptr (BAMF_TYPE_APPLICATION, new_view, (gpointer *) &matcher->priv->active_application))
{
g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view);
}
}
static void
bamf_matcher_on_active_window_changed (BamfDBusMatcher *proxy,
const char *old_path,
const char *new_path,
BamfMatcher *matcher)
{
BamfView *old_view;
BamfView *new_view;
BamfApplication *old_app;
BamfApplication *new_app;
BamfFactory *factory;
BamfMatcherPrivate *priv;
priv = matcher->priv;
old_app = priv->active_application;
new_app = old_app;
factory = _bamf_factory_get_default ();
old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_WINDOW);
new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_WINDOW);
track_ptr (BAMF_TYPE_WINDOW, new_view, (gpointer *) &priv->active_window);
if (BAMF_IS_WINDOW (new_view))
new_app = _bamf_factory_app_for_xid (factory, bamf_window_get_xid (BAMF_WINDOW (new_view)));
track_ptr (BAMF_TYPE_APPLICATION, (BamfView *) new_app, (gpointer *) &priv->active_application);
g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view);
if (new_app != old_app)
{
g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_app, new_app);
}
}
static void
bamf_matcher_on_stacking_order_changed (BamfDBusMatcher *proxy, BamfMatcher *matcher)
{
g_signal_emit (matcher, matcher_signals[STACKING_ORDER_CHANGED], 0);
}
static void
bamf_matcher_init (BamfMatcher *self)
{
BamfMatcherPrivate *priv;
GError *error = NULL;
priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self);
priv->cancellable = g_cancellable_new ();
priv->proxy = _bamf_dbus_matcher_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
BAMF_DBUS_MATCHER_PATH,
priv->cancellable, &error);
if (error)
{
g_warning ("Unable to get %s matcher: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");
g_error_free (error);
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
g_signal_connect (priv->proxy, "notify::g-name-owner",
G_CALLBACK (bamf_matcher_on_name_owner_changed), self);
g_signal_connect (priv->proxy, "view-opened",
G_CALLBACK (bamf_matcher_on_view_opened), self);
g_signal_connect (priv->proxy, "view-closed",
G_CALLBACK (bamf_matcher_on_view_closed), self);
g_signal_connect (priv->proxy, "active-application-changed",
G_CALLBACK (bamf_matcher_on_active_application_changed), self);
g_signal_connect (priv->proxy, "active-window-changed",
G_CALLBACK (bamf_matcher_on_active_window_changed), self);
g_signal_connect (priv->proxy, "stacking-order-changed",
G_CALLBACK (bamf_matcher_on_stacking_order_changed), self);
}
static void
bamf_matcher_dispose (GObject *object)
{
BamfMatcher *self = BAMF_MATCHER (object);
if (G_IS_DBUS_PROXY (self->priv->proxy))
{
g_signal_handlers_disconnect_by_data (self->priv->proxy, self);
g_object_unref (self->priv->proxy);
self->priv->proxy = NULL;
}
if (G_IS_CANCELLABLE (self->priv->cancellable))
{
g_cancellable_cancel (self->priv->cancellable);
g_object_unref (self->priv->cancellable);
}
G_OBJECT_CLASS (bamf_matcher_parent_class)->dispose (object);
}
/*
* Public Methods
*/
/**
* bamf_matcher_get_default:
*
* Returns the default matcher. This matcher is owned by bamf and shared between other callers.
*
* Returns: (transfer full): A new #BamfMatcher
*/
BamfMatcher *
bamf_matcher_get_default (void)
{
if (BAMF_IS_MATCHER (default_matcher))
return g_object_ref (default_matcher);
return (default_matcher = g_object_new (BAMF_TYPE_MATCHER, NULL));
}
/**
* bamf_matcher_get_active_application:
* @matcher: a #BamfMatcher
*
* Used to fetch the active #BamfApplication.
*
* Returns: (transfer none): The active #BamfApplication.
*/
BamfApplication *
bamf_matcher_get_active_application (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char *app = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (BAMF_IS_APPLICATION (priv->active_application))
{
if (!bamf_view_is_closed (BAMF_VIEW (priv->active_application)))
return priv->active_application;
}
if (!_bamf_dbus_matcher_call_active_application_sync (priv->proxy, &app, priv->cancellable, &error))
{
g_warning ("Failed to get active application: %s", error ? error->message : "");
g_error_free (error);
track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &priv->active_application);
return NULL;
}
BamfFactory *factory = _bamf_factory_get_default ();
view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
g_free (app);
if (!BAMF_IS_APPLICATION (view))
view = NULL;
track_ptr (BAMF_TYPE_APPLICATION, view, (gpointer *) &priv->active_application);
return priv->active_application;
}
/**
* bamf_matcher_get_active_window:
* @matcher: a #BamfMatcher
*
* Used to fetch the active #BamfWindow.
*
* Returns: (transfer none): The active #BamfWindow.
*/
BamfWindow *
bamf_matcher_get_active_window (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char *win = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (BAMF_IS_APPLICATION (priv->active_window))
{
if (!bamf_view_is_closed (BAMF_VIEW (priv->active_window)))
return priv->active_window;
}
if (!_bamf_dbus_matcher_call_active_window_sync (priv->proxy, &win, priv->cancellable, &error))
{
g_warning ("Failed to get active window: %s", error ? error->message : "");
g_error_free (error);
track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &priv->active_window);
return NULL;
}
BamfFactory *factory = _bamf_factory_get_default ();
view = _bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW);
g_free (win);
if (!BAMF_IS_WINDOW (view))
view = NULL;
track_ptr (BAMF_TYPE_WINDOW, view, (gpointer *) &priv->active_window);
return priv->active_window;
}
/**
* bamf_matcher_get_window_for_xid:
* @matcher: a #BamfMatcher
* @xid: The X11 Window ID to search for
*
* Used to fetch the #BamfWindow that wraps the given @window.
*
* Returns: (transfer none): The #BamfWindow representing the xid passed, or NULL if none exists.
*/
BamfWindow *
bamf_matcher_get_window_for_xid (BamfMatcher *matcher, guint32 xid)
{
BamfWindow *window;
BamfApplication *app;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
window = _bamf_factory_window_for_xid (_bamf_factory_get_default (), xid);
if (BAMF_IS_WINDOW (window))
return window;
app = bamf_matcher_get_application_for_xid (matcher, xid);
if (BAMF_IS_APPLICATION (app))
window = bamf_application_get_window_for_xid (app, xid);
return BAMF_IS_WINDOW (window) ? window : NULL;
}
/**
* bamf_matcher_get_application_for_window:
* @matcher: a #BamfMatcher
* @window: The window to look for
*
* Used to fetch the #BamfApplication containing the passed window.
*
* Returns: (transfer none): The #BamfApplication representing the xid passed, or NULL if none exists.
*/
BamfApplication *
bamf_matcher_get_application_for_window (BamfMatcher *matcher, BamfWindow *window)
{
g_return_val_if_fail (BAMF_IS_WINDOW (window), NULL);
return bamf_matcher_get_application_for_xid (matcher, bamf_window_get_xid(window));
}
/**
* bamf_matcher_get_application_for_xid:
* @matcher: a #BamfMatcher
* @xid: The XID to search for
*
* Used to fetch the #BamfApplication containing the passed xid.
*
* Returns: (transfer none): The #BamfApplication representing the xid passed, or NULL if none exists.
*/
BamfApplication *
bamf_matcher_get_application_for_xid (BamfMatcher *matcher, guint32 xid)
{
BamfMatcherPrivate *priv;
BamfView *view;
BamfFactory *factory;
char *app = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
factory = _bamf_factory_get_default ();
view = (BamfView*) _bamf_factory_app_for_xid (factory, xid);
if (BAMF_IS_APPLICATION (view))
return BAMF_APPLICATION (view);
if (!_bamf_dbus_matcher_call_application_for_xid_sync (priv->proxy, xid, &app, priv->cancellable, &error))
{
g_warning ("Failed to get application for xid %u: %s", xid, error ? error->message : "");
g_error_free (error);
return NULL;
}
view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
g_free (app);
if (!BAMF_IS_APPLICATION (view))
return NULL;
return BAMF_APPLICATION (view);
}
gboolean
bamf_matcher_application_is_running (BamfMatcher *matcher, const gchar *app)
{
BamfMatcherPrivate *priv;
BamfApplication *view;
gboolean running = FALSE;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE);
priv = matcher->priv;
view = _bamf_factory_app_for_file (_bamf_factory_get_default (), app, FALSE);
if (BAMF_IS_APPLICATION (view))
return bamf_view_is_running (BAMF_VIEW (view));
if (!_bamf_dbus_matcher_call_application_is_running_sync (priv->proxy,
app ? app : "",
&running,
priv->cancellable,
&error))
{
g_warning ("Failed to fetch running status: %s", error ? error->message : "");
g_error_free (error);
return FALSE;
}
return running;
}
/**
* bamf_matcher_get_applications:
* @matcher: a #BamfMatcher
*
* Used to fetch all #BamfApplication's running or not. Application authors who wish to only
* see running applications should use bamf_matcher_get_running_applications instead. The reason
* this method is needed is bamf will occasionally track applications which are not currently
* running for nefarious purposes.
*
* Returns: (element-type Bamf.Application) (transfer container): A list of #BamfApplication's.
*/
GList *
bamf_matcher_get_applications (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char **array = NULL;
int i, len;
GList *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_application_paths_sync (priv->proxy, &array, priv->cancellable, &error))
{
g_warning ("Failed to fetch applications paths: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!array)
return NULL;
BamfFactory *factory = _bamf_factory_get_default ();
len = g_strv_length (array);
for (i = len-1; i >= 0; --i)
{
view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_APPLICATION);
if (BAMF_IS_APPLICATION (view))
{
if (!g_list_find (result, view))
result = g_list_prepend (result, view);
}
}
g_strfreev (array);
return result;
}
/**
* bamf_matcher_get_windows:
* @matcher: a #BamfMatcher
*
* Used to fetch all windows that BAMF knows about.
*
* Returns: (element-type Bamf.Window) (transfer container): A list of #BamfWindow's.
*/
GList *
bamf_matcher_get_windows (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char **array = NULL;
int i, len;
GList *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_window_paths_sync (priv->proxy, &array, priv->cancellable, &error))
{
g_warning ("Failed to fetch windows paths: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!array)
return NULL;
BamfFactory *factory = _bamf_factory_get_default ();
len = g_strv_length (array);
for (i = len-1; i >= 0; --i)
{
view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_WINDOW);
if (BAMF_IS_WINDOW (view))
result = g_list_prepend (result, view);
}
g_strfreev (array);
return result;
}
/**
* bamf_matcher_get_window_stack_for_monitor:
* @matcher: a #BamfMatcher
* @monitor: the monitor you want the stack from, negative value to get all
*
* Used to fetch all windows that BAMF knows about in the requested screen,
* in stacking bottom-to-top order. If the @monitor is set to a negative value,
* then it fetches all the available windows in all monitors.
*
* Returns: (element-type Bamf.Window) (transfer container): A list of #BamfWindow's.
*/
GList *
bamf_matcher_get_window_stack_for_monitor (BamfMatcher *matcher, gint monitor)
{
BamfMatcherPrivate *priv;
BamfView *view;
char **array = NULL;
int i, len;
GList *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_window_stack_for_monitor_sync (priv->proxy, monitor,
&array, priv->cancellable,
&error))
{
g_warning ("Failed to fetch paths: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!array)
return NULL;
BamfFactory *factory = _bamf_factory_get_default ();
len = g_strv_length (array);
for (i = len-1; i >= 0; --i)
{
view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_WINDOW);
if (BAMF_IS_WINDOW (view))
result = g_list_prepend (result, view);
}
g_strfreev (array);
return result;
}
/**
* bamf_matcher_register_favorites:
* @matcher: a #BamfMatcher
* @favorites: (array): an array of strings, each containing an absolute path to a .desktop file
*
* Used to effect how bamf performs matching. Desktop files passed to this method will
* be prefered by bamf to system desktop files.
*/
void
bamf_matcher_register_favorites (BamfMatcher *matcher,
const gchar **favorites)
{
BamfMatcherPrivate *priv;
GError *error = NULL;
g_return_if_fail (BAMF_IS_MATCHER (matcher));
g_return_if_fail (favorites);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_register_favorites_sync (priv->proxy, favorites, priv->cancellable, &error))
{
g_warning ("Failed to register favorites: %s", error ? error->message : "");
g_error_free (error);
}
}
/**
* bamf_matcher_get_running_applications:
* @matcher: a #BamfMatcher
*
* Used to fetch all #BamfApplication's which are running.
*
* Returns: (element-type Bamf.Application) (transfer container): A list of #BamfApplication's.
*/
GList *
bamf_matcher_get_running_applications (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char **array = NULL;
int i, len;
GList *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_running_applications_sync (priv->proxy, &array, priv->cancellable, &error))
{
g_warning ("Failed to get running applications: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!array)
return NULL;
BamfFactory *factory = _bamf_factory_get_default ();
len = g_strv_length (array);
for (i = len-1; i >= 0; --i)
{
view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_APPLICATION);
if (BAMF_IS_APPLICATION (view))
result = g_list_prepend (result, view);
}
g_strfreev (array);
return result;
}
/**
* bamf_matcher_get_tabs:
* @matcher: a #BamfMatcher
*
* Used to fetch all #BamfView's representing tabs. Currently unused.
*
* Returns: (element-type Bamf.Tab) (transfer container): A list of #BamfTab's.
*/
GList *
bamf_matcher_get_tabs (BamfMatcher *matcher)
{
BamfMatcherPrivate *priv;
BamfView *view;
char **array = NULL;
int i, len;
GList *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_tab_paths_sync (priv->proxy, &array, priv->cancellable, &error))
{
g_warning ("Failed to get tabs: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
g_return_val_if_fail (array, NULL);
BamfFactory *factory = _bamf_factory_get_default ();
len = g_strv_length (array);
for (i = len-1; i >= 0; --i)
{
view = _bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_TAB);
if (BAMF_IS_TAB (view))
result = g_list_prepend (result, view);
}
g_strfreev (array);
return result;
}
/**
* bamf_matcher_get_xids_for_application:
* @matcher: a #BamfMatcher
*
* Used to fetch all xid's associated with an application. Useful for performing window
*
*
* Returns: (element-type guint32) (transfer full): A list of xids.
*/
GArray *
bamf_matcher_get_xids_for_application (BamfMatcher *matcher,
const gchar *application)
{
BamfMatcherPrivate *priv;
GArray *result = NULL;
GVariant *xids = NULL;
GVariantIter *iter;
GError *error = NULL;
guint32 xid = 0;
g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
priv = matcher->priv;
if (!_bamf_dbus_matcher_call_xids_for_application_sync (priv->proxy, application,
&xids, priv->cancellable,
&error))
{
g_warning ("Failed to get xids: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
g_return_val_if_fail (xids, NULL);
g_return_val_if_fail (g_variant_type_equal (g_variant_get_type (xids),
G_VARIANT_TYPE ("au")), NULL);
result = g_array_new (FALSE, TRUE, sizeof (guint32));
g_variant_get (xids, "au", &iter);
while (g_variant_iter_loop (iter, "u", &xid))
{
g_array_append_val (result, xid);
}
g_variant_iter_free (iter);
g_variant_unref (xids);
return result;
}
/**
* bamf_matcher_get_application_for_desktop_file:
* @matcher: a #BamfMatcher
* @desktop_file_path: Path to the desktop file
* @create_if_not_found: Create a #BamfApplication if one isn't found
*
* Returns: (transfer none): A #BamfApplication for given desktop file.
*/
BamfApplication *
bamf_matcher_get_application_for_desktop_file (BamfMatcher *matcher,
const gchar *desktop_file_path,
gboolean create_if_not_found)
{
BamfApplication *app;
const gchar ** favs;
app = _bamf_factory_app_for_file (_bamf_factory_get_default (), desktop_file_path, create_if_not_found);
if (app)
{
favs = g_new0 (const gchar *, 2);
favs[0] = desktop_file_path;
bamf_matcher_register_favorites (matcher, favs);
g_free (favs);
}
return app;
}
./lib/libbamf/bamf-tab.h 0000644 0000156 0000165 00000006237 12704153435 015075 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMF_TAB_H__
#define __BAMF_TAB_H__
#include
#include
G_BEGIN_DECLS
#define BAMF_TYPE_TAB (bamf_tab_get_type ())
#define BAMF_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_TAB, BamfTab))
#define BAMF_TAB_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BAMF_TYPE_TAB, BamfTab const))
#define BAMF_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BAMF_TYPE_TAB, BamfTabClass))
#define BAMF_IS_TAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BAMF_TYPE_TAB))
#define BAMF_IS_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BAMF_TYPE_TAB))
#define BAMF_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_TAB, BamfTabClass))
typedef struct _BamfTab BamfTab;
typedef struct _BamfTabClass BamfTabClass;
typedef struct _BamfTabPrivate BamfTabPrivate;
struct _BamfTab
{
BamfView parent;
BamfTabPrivate *priv;
};
struct _BamfTabClass
{
BamfViewClass parent_class;
const gchar * (*get_desktop_name) (BamfTab *self);
const gchar * (*get_location) (BamfTab *self);
guint64 (*get_xid) (BamfTab *self);
gboolean (*get_is_foreground_tab) (BamfTab *self);
/*< private >*/
void (*_tab_padding1) (void);
void (*_tab_padding2) (void);
void (*_tab_padding3) (void);
void (*_tab_padding4) (void);
};
typedef void (*BamfTabPreviewReadyCallback) (BamfTab *self, const gchar *preview_data, gpointer user_data);
GType bamf_tab_get_type (void) G_GNUC_CONST;
gboolean bamf_tab_raise (BamfTab *self);
gboolean bamf_tab_close (BamfTab *self);
void bamf_tab_request_preview (BamfTab *self,
BamfTabPreviewReadyCallback callback,
gpointer user_data);
const gchar *bamf_tab_get_desktop_name (BamfTab *self);
const gchar *bamf_tab_get_location (BamfTab *self);
guint64 bamf_tab_get_xid (BamfTab *self);
gboolean bamf_tab_get_is_foreground_tab (BamfTab *self);
G_END_DECLS
#endif /* __BAMF_TAB_H__ */
./lib/libbamf/bamf-window.c 0000644 0000156 0000165 00000027703 12704153435 015632 0 ustar jenkins jenkins /*
* Copyright 2010-2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
/**
* SECTION:bamf-window
* @short_description: The base class for all windows
*
* #BamfWindow is the base class that all windows need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-view-private.h"
#include "bamf-window.h"
#include "bamf-factory.h"
G_DEFINE_TYPE (BamfWindow, bamf_window, BAMF_TYPE_VIEW);
#define BAMF_WINDOW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_WINDOW, BamfWindowPrivate))
struct _BamfWindowPrivate
{
BamfDBusItemWindow *proxy;
guint32 xid;
guint32 pid;
time_t last_active;
gint monitor;
BamfWindowType type;
BamfWindowMaximizationType maximized;
};
enum
{
MONITOR_CHANGED,
MAXIMIZED_CHANGED,
LAST_SIGNAL,
};
static guint window_signals[LAST_SIGNAL] = { 0 };
time_t
bamf_window_last_active (BamfWindow *self)
{
g_return_val_if_fail (BAMF_IS_WINDOW (self), 0);
if (BAMF_WINDOW_GET_CLASS (self)->last_active)
return BAMF_WINDOW_GET_CLASS (self)->last_active (self);
return self->priv->last_active;
}
/**
* bamf_window_get_transient:
* @self: a #BamfWindow
*
* Returns: (transfer none) (allow-none): A transient for this #BamfWindow.
*/
BamfWindow *
bamf_window_get_transient (BamfWindow *self)
{
BamfWindowPrivate *priv;
BamfView *transient;
char *path = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
if (BAMF_WINDOW_GET_CLASS (self)->get_transient)
return BAMF_WINDOW_GET_CLASS (self)->get_transient (self);
priv = self->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return NULL;
if (!_bamf_dbus_item_window_call_transient_sync (priv->proxy, &path,
CANCELLABLE (self), &error))
{
g_warning ("Failed to fetch path: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!path)
return NULL;
if (path[0] == '\0')
{
g_free (path);
return NULL;
}
BamfFactory *factory = _bamf_factory_get_default ();
transient = _bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
g_free (path);
if (!BAMF_IS_WINDOW (transient))
return NULL;
return BAMF_WINDOW (transient);
}
BamfWindowType
bamf_window_get_window_type (BamfWindow *self)
{
BamfWindowPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
if (BAMF_WINDOW_GET_CLASS (self)->get_window_type)
return BAMF_WINDOW_GET_CLASS (self)->get_window_type (self);
priv = self->priv;
if (priv->type != BAMF_WINDOW_UNKNOWN)
return priv->type;
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return priv->type;
if (!_bamf_dbus_item_window_call_window_type_sync (priv->proxy, &priv->type,
CANCELLABLE (self), &error))
{
priv->type = BAMF_WINDOW_UNKNOWN;
g_warning ("Failed to fetch type: %s", error ? error->message : "");
g_error_free (error);
}
return priv->type;
}
guint32
bamf_window_get_pid (BamfWindow *self)
{
BamfWindowPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
if (BAMF_WINDOW_GET_CLASS (self)->get_pid)
return BAMF_WINDOW_GET_CLASS (self)->get_pid (self);
priv = self->priv;
if (priv->pid != 0)
return priv->pid;
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return priv->pid;
if (!_bamf_dbus_item_window_call_get_pid_sync (priv->proxy, &priv->pid,
CANCELLABLE (self), &error))
{
priv->pid = 0;
g_warning ("Failed to fetch pid: %s", error ? error->message : "");
g_error_free (error);
}
return priv->pid;
}
guint32
bamf_window_get_xid (BamfWindow *self)
{
BamfWindowPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), FALSE);
if (BAMF_WINDOW_GET_CLASS (self)->get_xid)
return BAMF_WINDOW_GET_CLASS (self)->get_xid (self);
priv = self->priv;
if (priv->xid != 0)
return priv->xid;
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return priv->xid;
if (!_bamf_dbus_item_window_call_get_xid_sync (priv->proxy, &priv->xid,
CANCELLABLE (self), &error))
{
priv->xid = 0;
g_warning ("Failed to fetch xid: %s", error ? error->message : "");
g_error_free (error);
}
return priv->xid;
}
gchar *
bamf_window_get_utf8_prop (BamfWindow *self, const char* xprop)
{
BamfWindowPrivate *priv;
char *result = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), NULL);
g_return_val_if_fail (xprop, NULL);
if (BAMF_WINDOW_GET_CLASS (self)->get_utf8_prop)
return BAMF_WINDOW_GET_CLASS (self)->get_utf8_prop (self, xprop);
priv = self->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return NULL;
if (!_bamf_dbus_item_window_call_xprop_sync (priv->proxy, xprop, &result,
CANCELLABLE (self), &error))
{
g_warning ("Failed to fetch property `%s': %s", xprop, error ? error->message : "");
g_error_free (error);
return NULL;
}
if (result && result[0] == '\0')
{
g_free (result);
result = NULL;
}
return result;
}
gint
bamf_window_get_monitor (BamfWindow *self)
{
BamfWindowPrivate *priv;
gint monitor = -2;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
if (BAMF_WINDOW_GET_CLASS (self)->get_monitor)
return BAMF_WINDOW_GET_CLASS (self)->get_monitor (self);
priv = self->priv;
if (priv->monitor != -2 || !_bamf_view_remote_ready (BAMF_VIEW (self)))
{
return priv->monitor;
}
if (!_bamf_dbus_item_window_call_monitor_sync (priv->proxy, &monitor,
CANCELLABLE (self), &error))
{
g_warning ("Failed to fetch monitor: %s", error ? error->message : "");
g_error_free (error);
monitor = -1;
}
return monitor;
}
BamfWindowMaximizationType
bamf_window_maximized (BamfWindow *self)
{
BamfWindowPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_WINDOW (self), -1);
if (BAMF_WINDOW_GET_CLASS (self)->maximized)
return BAMF_WINDOW_GET_CLASS (self)->maximized (self);
priv = self->priv;
if (priv->maximized != -1 || !_bamf_view_remote_ready (BAMF_VIEW (self)))
{
return priv->maximized;
}
if (!_bamf_dbus_item_window_call_maximized_sync (priv->proxy, (gint*) &priv->maximized,
CANCELLABLE (self), &error))
{
priv->maximized = -1;
g_warning ("Failed to fetch maximized state: %s", error->message);
g_error_free (error);
}
return priv->maximized;
}
static void
bamf_window_active_changed (BamfView *view, gboolean active)
{
BamfWindow *self;
g_return_if_fail (BAMF_IS_WINDOW (view));
self = BAMF_WINDOW (view);
if (active)
self->priv->last_active = time (NULL);
}
static void
bamf_window_on_monitor_changed (BamfDBusItemWindow *proxy, gint old, gint new, BamfWindow *self)
{
self->priv->monitor = new;
g_signal_emit (G_OBJECT (self), window_signals[MONITOR_CHANGED], 0, old, new);
}
static void
bamf_window_on_maximized_changed (BamfDBusItemWindow *proxy, gint old, gint new, BamfWindow *self)
{
self->priv->maximized = new;
g_signal_emit (G_OBJECT (self), window_signals[MAXIMIZED_CHANGED], 0, old, new);
}
static void
bamf_window_unset_proxy (BamfWindow *self)
{
BamfWindowPrivate *priv;
g_return_if_fail (BAMF_IS_WINDOW (self));
priv = self->priv;
if (!G_IS_DBUS_PROXY (priv->proxy))
return;
g_signal_handlers_disconnect_by_data (priv->proxy, self);
g_object_unref (priv->proxy);
priv->proxy = NULL;
}
static void
bamf_window_set_path (BamfView *view, const char *path)
{
BamfWindow *self;
BamfWindowPrivate *priv;
GError *error = NULL;
self = BAMF_WINDOW (view);
priv = self->priv;
bamf_window_unset_proxy (self);
priv->proxy = _bamf_dbus_item_window_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
path, CANCELLABLE (self),
&error);
if (!G_IS_DBUS_PROXY (priv->proxy))
{
g_error ("Unable to get %s window: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");
g_error_free (error);
return;
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
priv->xid = bamf_window_get_xid (self);
priv->type = bamf_window_get_window_type (self);
priv->monitor = bamf_window_get_monitor (self);
priv->maximized = bamf_window_maximized (self);
g_signal_connect (priv->proxy, "monitor-changed",
G_CALLBACK (bamf_window_on_monitor_changed), self);
g_signal_connect (priv->proxy, "maximized-changed",
G_CALLBACK (bamf_window_on_maximized_changed), self);
}
static void
bamf_window_dispose (GObject *object)
{
BamfWindow *self = BAMF_WINDOW (object);
bamf_window_unset_proxy (self);
if (G_OBJECT_CLASS (bamf_window_parent_class)->dispose)
G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);
}
static void
bamf_window_class_init (BamfWindowClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
g_type_class_add_private (obj_class, sizeof (BamfWindowPrivate));
obj_class->dispose = bamf_window_dispose;
view_class->active_changed = bamf_window_active_changed;
view_class->set_path = bamf_window_set_path;
window_signals[MONITOR_CHANGED] =
g_signal_new (BAMF_WINDOW_SIGNAL_MONITOR_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfWindowClass, monitor_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_INT, G_TYPE_INT);
window_signals[MAXIMIZED_CHANGED] =
g_signal_new (BAMF_WINDOW_SIGNAL_MAXIMIZED_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfWindowClass, maximized_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_INT, G_TYPE_INT);
}
static void
bamf_window_init (BamfWindow *self)
{
BamfWindowPrivate *priv;
priv = self->priv = BAMF_WINDOW_GET_PRIVATE (self);
priv->xid = 0;
priv->pid = 0;
priv->type = BAMF_WINDOW_UNKNOWN;
priv->monitor = -2;
priv->maximized = -1;
}
BamfWindow *
bamf_window_new (const char * path)
{
BamfWindow *self = g_object_new (BAMF_TYPE_WINDOW, NULL);
_bamf_view_set_path (BAMF_VIEW (self), path);
return self;
}
./lib/libbamf/bamf-matcher.h 0000644 0000156 0000165 00000011304 12704153435 015741 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_MATCHER_H_
#define _BAMF_MATCHER_H_
#include
#include
#include
G_BEGIN_DECLS
#define BAMF_TYPE_MATCHER (bamf_matcher_get_type ())
#define BAMF_MATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_MATCHER, BamfMatcher))
#define BAMF_MATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_MATCHER, BamfMatcherClass))
#define BAMF_IS_MATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_MATCHER))
#define BAMF_IS_MATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_MATCHER))
#define BAMF_MATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_MATCHER, BamfMatcherClass))
#define BAMF_MATCHER_SIGNAL_VIEW_OPENED "view-opened"
#define BAMF_MATCHER_SIGNAL_VIEW_CLOSED "view-closed"
#define BAMF_MATCHER_SIGNAL_ACTIVE_APPLICATION_CHANGED "active-application-changed"
#define BAMF_MATCHER_SIGNAL_ACTIVE_WINDOW_CHANGED "active-window-changed"
#define BAMF_MATCHER_SIGNAL_STACKING_ORDER_CHANGED "stacking-order-changed"
typedef struct _BamfMatcher BamfMatcher;
typedef struct _BamfMatcherClass BamfMatcherClass;
typedef struct _BamfMatcherPrivate BamfMatcherPrivate;
struct _BamfMatcher
{
GObject parent;
BamfMatcherPrivate *priv;
};
struct _BamfMatcherClass
{
GObjectClass parent_class;
/*< private >*/
void (*_matcher_padding1) (void);
void (*_matcher_padding2) (void);
void (*_matcher_padding3) (void);
void (*_matcher_padding4) (void);
void (*_matcher_padding5) (void);
void (*_matcher_padding6) (void);
};
GType bamf_matcher_get_type (void) G_GNUC_CONST;
BamfMatcher * bamf_matcher_get_default (void);
BamfApplication * bamf_matcher_get_active_application (BamfMatcher *matcher);
BamfWindow * bamf_matcher_get_active_window (BamfMatcher *matcher);
BamfWindow * bamf_matcher_get_window_for_xid (BamfMatcher *matcher,
guint32 xid);
BamfApplication * bamf_matcher_get_application_for_xid (BamfMatcher *matcher,
guint32 xid);
BamfApplication * bamf_matcher_get_application_for_window (BamfMatcher *matcher,
BamfWindow *window);
gboolean bamf_matcher_application_is_running (BamfMatcher *matcher,
const gchar *desktop_file);
GList * bamf_matcher_get_applications (BamfMatcher *matcher);
void bamf_matcher_register_favorites (BamfMatcher *matcher,
const gchar **favorites);
GList * bamf_matcher_get_running_applications (BamfMatcher *matcher);
GList * bamf_matcher_get_tabs (BamfMatcher *matcher);
GArray * bamf_matcher_get_xids_for_application (BamfMatcher *matcher,
const gchar *desktop_file);
GList * bamf_matcher_get_windows (BamfMatcher *matcher);
GList * bamf_matcher_get_window_stack_for_monitor (BamfMatcher *matcher,
gint monitor);
BamfApplication * bamf_matcher_get_application_for_desktop_file (BamfMatcher *matcher,
const gchar *desktop_file_path,
gboolean create_if_not_found);
G_END_DECLS
#endif
./lib/libbamf/Makefile.am 0000644 0000156 0000165 00000005512 12704153435 015302 0 ustar jenkins jenkins -include $(INTROSPECTION_MAKEFILE)
LIBBAMF_PRIVATE_LIB = $(top_builddir)/lib/libbamf-private/libbamf-private.la
libbamf_sources = \
bamf-application.c \
bamf-control.c \
bamf-matcher.c \
bamf-view.c \
bamf-window.c \
bamf-factory.c \
bamf-tab.c \
$(NULL)
libbamf_headers = \
bamf-application.h \
bamf-control.h \
bamf-matcher.h \
bamf-view.h \
bamf-window.h \
bamf-tab.h \
libbamf.h \
$(NULL)
libbamf_private_headers = \
bamf-factory.h \
bamf-application-private.h \
bamf-view-private.h \
$(NULL)
libbamf_la_SOURCES = \
$(libbamf_built_sources) \
$(libbamf_private_headers) \
$(libbamf_headers) \
$(libbamf_sources) \
$(NULL)
libbamf_la_LIBADD = \
$(LIBBAMF_PRIVATE_LIB) \
$(LIBWSBIND_LIBS) \
$(GLIB_LIBS) \
$(COVERAGE_LIBS) \
$(NULL)
libbamf_la_CFLAGS = \
-Wall -std=c99 \
-fPIC \
-DDATADIR=\""$(datadir)"\" \
-I$(srcdir) \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
$(COVERAGE_CFLAGS) \
$(LIBWSBIND_CFLAGS) \
$(GLIB_CFLAGS) \
$(NULL)
libbamf_la_LDFLAGS = \
-shared \
-export-symbols-regex "^bamf_" \
-version-info $(LIBBAMF_SONAME) \
$(COVERAGE_LDFLAGS) \
$(NULL)
lib_LTLIBRARIES = libbamf3.la
libbamf3_la_SOURCES = $(libbamf_la_SOURCES)
libbamf3_la_LIBADD = $(libbamf_la_LIBADD)
libbamf3_la_CFLAGS = $(libbamf_la_CFLAGS)
libbamf3_la_LDFLAGS = $(libbamf_la_LDFLAGS)
libbamf_includedir=$(includedir)/libbamf$(LIBBAMF_VER)/libbamf
libbamf_include_HEADERS = \
$(libbamf_headers)
libbamf_pcdir = $(libdir)/pkgconfig
libbamf_pc_DATA = \
libbamf$(LIBBAMF_VER).pc
BUILT_SOURCES = \
$(libbamf_gdbus_files) \
$(NULL)
DISTCLEANFILES = \
$(libbamf_built_sources) \
$(NULL)
CLEANFILES = \
$(libbamf_built_sources) \
$(NULL)
#########################
# GObject Introsepction
#########################
if HAVE_INTROSPECTION
INTROSPECTION_GIRS = Bamf-3.gir
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir)
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
introspection_sources = \
$(libbamf_headers) \
$(libbamf_sources) \
$(NULL)
Bamf-3.gir: libbamf$(LIBBAMF_VER).la
Bamf_3_gir_INCLUDES = GObject-2.0 GLib-2.0
Bamf_3_gir_SCANNERFLAGS = --warn-all --c-include='libbamf/libbamf.h'
Bamf_3_gir_CFLAGS = \
$(DBUS_CFLAGS) \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
$(NULL)
Bamf_3_gir_LIBS = libbamf$(LIBBAMF_VER).la
Bamf_3_gir_FILES = $(introspection_sources)
Bamf_3_gir_EXPORT_PACKAGES = libbamf$(LIBBAMF_VER)
girdir = $(INTROSPECTION_GIRDIR)
gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(INTROSPECTION_TYPELIBDIR)
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
CLEANFILES += $(gir_DATA) $(typelib_DATA)
endif
#########################
# VAPI Files
#########################
if HAVE_INTROSPECTION
vapidir = $(datadir)/vala/vapi
vapi_DATA = libbamf$(LIBBAMF_VER).vapi
$(vapi_DATA): $(INTROSPECTION_GIRS)
$(AM_V_GEN)$(VALA_API_GEN) --library=$(@:.vapi=) $<
CLEANFILES += $(vapi_DATA)
endif
./lib/libbamf/bamf-factory.h 0000644 0000156 0000165 00000007014 12704153435 015770 0 ustar jenkins jenkins /*
* Copyright 2010 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_FACTORY_H_
#define _BAMF_FACTORY_H_
#include
#include
#include
#include
G_BEGIN_DECLS
#define BAMF_TYPE_FACTORY (bamf_factory_get_type ())
#define BAMF_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_FACTORY, BamfFactory))
#define BAMF_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_FACTORY, BamfFactoryClass))
#define BAMF_IS_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_FACTORY))
#define BAMF_IS_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_FACTORY))
#define BAMF_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_FACTORY, BamfFactoryClass))
typedef struct _BamfFactory BamfFactory;
typedef struct _BamfFactoryClass BamfFactoryClass;
typedef struct _BamfFactoryPrivate BamfFactoryPrivate;
typedef enum
{
BAMF_FACTORY_VIEW,
BAMF_FACTORY_WINDOW,
BAMF_FACTORY_APPLICATION,
BAMF_FACTORY_TAB,
BAMF_FACTORY_NONE
} BamfFactoryViewType;
struct _BamfFactory
{
GObject parent;
BamfFactoryPrivate *priv;
};
struct _BamfFactoryClass
{
GObjectClass parent_class;
};
GType bamf_factory_get_type (void) G_GNUC_CONST;
BamfView * _bamf_factory_view_for_path (BamfFactory * factory,
const char * path);
BamfView * _bamf_factory_view_for_path_type (BamfFactory * factory,
const char * path,
BamfFactoryViewType type);
BamfView * _bamf_factory_view_for_path_type_str (BamfFactory * factory,
const char * path,
const char * type);
BamfWindow * _bamf_factory_window_for_xid (BamfFactory * factory,
guint32 xid);
BamfApplication * _bamf_factory_app_for_file (BamfFactory * factory,
const char * path,
gboolean create);
BamfApplication * _bamf_factory_app_for_xid (BamfFactory * factory,
guint32 xid);
BamfFactory * _bamf_factory_get_default (void);
G_END_DECLS
#endif
./lib/libbamf/libbamf.h 0000644 0000156 0000165 00000002274 12704153435 015015 0 ustar jenkins jenkins /*
* Copyright 2010 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
*
*/
#ifndef __LIBBAMF_H__
#define __LIBBAMF_H__
#include
#include
#include
#include
#include
#include
#endif
./lib/libbamf/libbamf3.pc.in 0000644 0000156 0000165 00000000444 12704153435 015655 0 ustar jenkins jenkins prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libbamf3
Description: C Convenience library for bamf d-bus server.
Version: @VERSION@
Requires: glib-2.0 gio-2.0
Libs: -L${libdir} -lbamf3
Cflags: -I${includedir}/libbamf3 -I${libdir}/libbamf3/include
./lib/libbamf/bamf-control.h 0000644 0000156 0000165 00000006151 12704153435 016002 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_CONTROL_H_
#define _BAMF_CONTROL_H_
#include
#include "bamf-application.h"
G_BEGIN_DECLS
#define BAMF_TYPE_CONTROL (bamf_control_get_type ())
#define BAMF_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_CONTROL, BamfControl))
#define BAMF_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_CONTROL, BamfControlClass))
#define BAMF_IS_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_CONTROL))
#define BAMF_IS_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_CONTROL))
#define BAMF_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_CONTROL, BamfControlClass))
typedef struct _BamfControl BamfControl;
typedef struct _BamfControlClass BamfControlClass;
typedef struct _BamfControlPrivate BamfControlPrivate;
struct _BamfControl
{
GObject parent;
BamfControlPrivate *priv;
};
struct _BamfControlClass
{
GObjectClass parent_class;
/*< private >*/
void (*_control_padding1) (void);
void (*_control_padding2) (void);
void (*_control_padding3) (void);
void (*_control_padding4) (void);
void (*_control_padding5) (void);
void (*_control_padding6) (void);
};
GType bamf_control_get_type (void) G_GNUC_CONST;
BamfControl * bamf_control_get_default (void);
void bamf_control_insert_desktop_file (BamfControl *control,
const gchar *desktop_file);
void bamf_control_create_local_desktop_file (BamfControl *control,
BamfApplication *application);
void bamf_control_register_application_for_pid (BamfControl *control,
const gchar *desktop_file,
gint32 pid);
void bamf_control_set_approver_behavior (BamfControl *control,
gint32 behavior);
G_END_DECLS
#endif
./lib/libbamf/bamf-application-private.h 0000644 0000156 0000165 00000001754 12704153435 020301 0 ustar jenkins jenkins /*
* bamf-application-private.h
* This file is part of BAMF
*
* Copyright (C) 2012 - Marco Trevisan (Treviño)
*
* BAMF is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* BAMF 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 BAMF; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef _BAMF_APPLICATION_PRIVATE_H_
#define _BAMF_APPLICATION_PRIVATE_H_
#include
GList * _bamf_application_get_cached_xids (BamfApplication *app);
#endif
./lib/libbamf/bamf-application.h 0000644 0000156 0000165 00000007404 12704153435 016627 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_APPLICATION_H_
#define _BAMF_APPLICATION_H_
#include
#include
#include
G_BEGIN_DECLS
#define BAMF_TYPE_APPLICATION (bamf_application_get_type ())
#define BAMF_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_APPLICATION, BamfApplication))
#define BAMF_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_APPLICATION, BamfApplicationClass))
#define BAMF_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_APPLICATION))
#define BAMF_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_APPLICATION))
#define BAMF_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_APPLICATION, BamfApplicationClass))
#define BAMF_APPLICATION_SIGNAL_DESKTOP_FILE_UPDATED "desktop-file-updated"
#define BAMF_APPLICATION_SIGNAL_WINDOW_ADDED "window-added"
#define BAMF_APPLICATION_SIGNAL_WINDOW_REMOVED "window-removed"
typedef struct _BamfApplication BamfApplication;
typedef struct _BamfApplicationClass BamfApplicationClass;
typedef struct _BamfApplicationPrivate BamfApplicationPrivate;
struct _BamfApplication
{
BamfView parent;
BamfApplicationPrivate *priv;
};
struct _BamfApplicationClass
{
BamfViewClass parent_class;
/*< private >*/
void (*_application_padding1) (void);
void (*_application_padding2) (void);
void (*_application_padding3) (void);
void (*_application_padding4) (void);
void (*_application_padding5) (void);
void (*_application_padding6) (void);
};
GType bamf_application_get_type (void) G_GNUC_CONST;
const gchar * bamf_application_get_application_type (BamfApplication *application);
const gchar * bamf_application_get_desktop_file (BamfApplication *application);
gchar ** bamf_application_get_supported_mime_types (BamfApplication *application);
GList * bamf_application_get_windows (BamfApplication *application);
GArray * bamf_application_get_xids (BamfApplication *application);
BamfView * bamf_application_get_focusable_child (BamfApplication *application);
gboolean bamf_application_get_show_menu_stubs (BamfApplication *application);
BamfWindow * bamf_application_get_window_for_xid (BamfApplication *application,
guint32 xid);
/* Deprecated symbols */
G_GNUC_DEPRECATED
gboolean bamf_application_get_application_menu (BamfApplication *application,
gchar **name,
gchar **object_path);
G_END_DECLS
#endif
./lib/libbamf/bamf-factory.c 0000644 0000156 0000165 00000034417 12704153435 015772 0 ustar jenkins jenkins /*
* Copyright 2010-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño)
*
*/
/**
* SECTION:bamf-factory
* @short_description: The base class for all factorys
*
* #BamfFactory is the base class that all factorys need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-factory.h"
#include "bamf-application-private.h"
#include "bamf-view-private.h"
G_DEFINE_TYPE (BamfFactory, bamf_factory, G_TYPE_OBJECT);
#define BAMF_FACTORY_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_FACTORY, BamfFactoryPrivate))
struct _BamfFactoryPrivate
{
GHashTable *open_views;
GList *allocated_views;
};
static BamfFactory *static_factory = NULL;
static void on_view_weak_unref (BamfFactory *self, BamfView *view_was_here);
static void on_view_closed (BamfView *view, BamfFactory *self);
static void
bamf_factory_dispose (GObject *object)
{
GList *l, *next;
BamfFactory *self = BAMF_FACTORY (object);
if (self->priv->allocated_views)
{
for (l = self->priv->allocated_views, next = NULL; l; l = next)
{
g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify) on_view_weak_unref, self);
g_signal_handlers_disconnect_by_func (l->data, on_view_closed, self);
next = l->next;
g_list_free1 (l);
}
self->priv->allocated_views = NULL;
}
if (self->priv->open_views)
{
g_hash_table_remove_all (self->priv->open_views);
self->priv->open_views = NULL;
}
G_OBJECT_CLASS (bamf_factory_parent_class)->dispose (object);
}
static void
bamf_factory_finalize (GObject *object)
{
BamfFactory *self = BAMF_FACTORY (object);
if (self->priv->open_views)
{
g_hash_table_destroy (self->priv->open_views);
self->priv->open_views = NULL;
}
static_factory = NULL;
G_OBJECT_CLASS (bamf_factory_parent_class)->finalize (object);
}
static void
bamf_factory_class_init (BamfFactoryClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
obj_class->dispose = bamf_factory_dispose;
obj_class->finalize = bamf_factory_finalize;
g_type_class_add_private (obj_class, sizeof (BamfFactoryPrivate));
}
static void
bamf_factory_init (BamfFactory *self)
{
self->priv = BAMF_FACTORY_GET_PRIVATE (self);
self->priv->open_views = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
}
static void
on_view_closed (BamfView *view, BamfFactory *self)
{
const char *path;
gboolean removed;
removed = FALSE;
path = _bamf_view_get_path (view);
g_signal_handlers_disconnect_by_func (view, on_view_closed, self);
if (path)
{
removed = g_hash_table_remove (self->priv->open_views, path);
}
if (G_UNLIKELY (!removed))
{
/* Unlikely to happen, but who knows... */
GHashTableIter iter;
gpointer value;
g_hash_table_iter_init (&iter, self->priv->open_views);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
if (value == view)
{
g_hash_table_iter_remove (&iter);
removed = TRUE;
break;
}
}
}
}
static void
on_view_weak_unref (BamfFactory *self, BamfView *view_was_here)
{
self->priv->allocated_views = g_list_remove (self->priv->allocated_views, view_was_here);
}
static void
bamf_factory_track_view (BamfFactory *self, BamfView *view)
{
g_return_if_fail (BAMF_IS_VIEW (view));
if (g_list_find (self->priv->allocated_views, view))
return;
g_object_weak_ref (G_OBJECT (view), (GWeakNotify) on_view_weak_unref, self);
self->priv->allocated_views = g_list_prepend (self->priv->allocated_views, view);
}
static void
bamf_factory_register_view (BamfFactory *self, BamfView *view, const char *path)
{
g_return_if_fail (BAMF_IS_VIEW (view));
g_return_if_fail (path != NULL);
g_object_ref_sink (view);
g_hash_table_insert (self->priv->open_views, g_strdup (path), view);
g_signal_connect_after (G_OBJECT (view), BAMF_VIEW_SIGNAL_CLOSED,
G_CALLBACK (on_view_closed), self);
}
BamfWindow *
_bamf_factory_window_for_xid (BamfFactory * factory,
guint32 xid)
{
BamfWindow *result = NULL, *win;
GList *l;
for (l = factory->priv->allocated_views; l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
if (bamf_view_is_closed (l->data))
continue;
win = BAMF_WINDOW (l->data);
if (bamf_window_get_xid (win) == xid)
{
result = win;
break;
}
}
return result;
}
BamfApplication *
_bamf_factory_app_for_file (BamfFactory * factory,
const char * path,
gboolean create)
{
BamfApplication *result = NULL, *app;
GList *l;
/* check if result is available in known allocated_views */
for (l = factory->priv->allocated_views; l; l = l->next)
{
if (!BAMF_IS_APPLICATION (l->data))
continue;
app = BAMF_APPLICATION (l->data);
if (g_strcmp0 (bamf_application_get_desktop_file (app), path) == 0)
{
result = app;
break;
}
}
/* else create new */
if (!result && create)
{
/* delay registration until match time */
result = bamf_application_new_favorite (path);
if (BAMF_IS_APPLICATION (result))
{
bamf_factory_track_view (factory, BAMF_VIEW (result));
}
}
return result;
}
BamfApplication *
_bamf_factory_app_for_xid (BamfFactory * factory,
guint32 xid)
{
BamfApplication *result = NULL, *app;
GList *l, *local_children;
for (l = factory->priv->allocated_views; l; l = l->next)
{
if (!BAMF_IS_APPLICATION (l->data))
continue;
if (bamf_view_is_closed (l->data))
continue;
app = BAMF_APPLICATION (l->data);
local_children = _bamf_application_get_cached_xids (app);
if (g_list_find (local_children, GUINT_TO_POINTER (xid)))
{
result = app;
break;
}
}
return result;
}
static
BamfFactoryViewType compute_factory_type_by_str (const char *type)
{
BamfFactoryViewType factory_type = BAMF_FACTORY_NONE;
if (type && type[0] != '\0')
{
if (g_strcmp0 (type, "window") == 0)
{
factory_type = BAMF_FACTORY_WINDOW;
}
else if (g_strcmp0 (type, "application") == 0)
{
factory_type = BAMF_FACTORY_APPLICATION;
}
else if (g_strcmp0 (type, "tab") == 0)
{
factory_type = BAMF_FACTORY_TAB;
}
else if (g_strcmp0 (type, "view") == 0)
{
factory_type = BAMF_FACTORY_VIEW;
}
}
return factory_type;
}
BamfView *
_bamf_factory_view_for_path (BamfFactory * factory, const char * path)
{
return _bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_NONE);
}
BamfView *
_bamf_factory_view_for_path_type_str (BamfFactory * factory, const char * path,
const char * type)
{
g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
BamfFactoryViewType factory_type = compute_factory_type_by_str (type);
return _bamf_factory_view_for_path_type (factory, path, factory_type);
}
BamfView *
_bamf_factory_view_for_path_type (BamfFactory * factory, const char * path,
BamfFactoryViewType type)
{
GHashTable *views;
BamfView *view;
BamfDBusItemView *vproxy;
GList *l;
g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
if (!path || path[0] == '\0')
return NULL;
views = factory->priv->open_views;
view = g_hash_table_lookup (views, path);
if (BAMF_IS_VIEW (view))
return view;
if (type == BAMF_FACTORY_NONE)
{
vproxy = _bamf_dbus_item_view_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
path, NULL, NULL);
if (G_IS_DBUS_PROXY (vproxy))
{
char *type_str = NULL;
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (vproxy), BAMF_DBUS_DEFAULT_TIMEOUT);
_bamf_dbus_item_view_call_view_type_sync (vproxy, &type_str, NULL, NULL);
type = compute_factory_type_by_str (type_str);
g_free (type_str);
g_object_unref (vproxy);
}
}
switch (type)
{
case BAMF_FACTORY_VIEW:
view = g_object_new (BAMF_TYPE_VIEW, NULL);
break;
case BAMF_FACTORY_WINDOW:
view = BAMF_VIEW (bamf_window_new (path));
break;
case BAMF_FACTORY_APPLICATION:
view = BAMF_VIEW (bamf_application_new (path));
break;
case BAMF_FACTORY_TAB:
view = BAMF_VIEW (bamf_tab_new (path));
break;
case BAMF_FACTORY_NONE:
view = NULL;
break;
}
BamfView *matched_view = NULL;
/* handle case where another allocated (but closed) view exists and the new
* one matches it, so that we can reuse it. */
if (BAMF_IS_APPLICATION (view))
{
const char *local_desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (view));
GList *local_children = _bamf_application_get_cached_xids (BAMF_APPLICATION (view));
char *local_name = bamf_view_get_name (view);
gboolean matched_by_name = FALSE;
for (l = factory->priv->allocated_views; l; l = l->next)
{
if (!BAMF_IS_APPLICATION (l->data))
continue;
if (!bamf_view_is_closed (l->data))
continue;
BamfView *list_view = BAMF_VIEW (l->data);
BamfApplication *list_app = BAMF_APPLICATION (l->data);
const char *list_desktop_file = bamf_application_get_desktop_file (list_app);
/* We try to match applications by desktop files */
if (local_desktop_file && g_strcmp0 (local_desktop_file, list_desktop_file) == 0)
{
matched_view = list_view;
break;
}
/* If the primary search doesn't give out any result, we fallback
* to children window comparison */
if (!list_desktop_file)
{
GList *list_children, *ll;
list_children = _bamf_application_get_cached_xids (list_app);
for (ll = local_children; ll; ll = ll->next)
{
if (g_list_find (list_children, ll->data))
{
/* Not stopping the parent loop here is intended, as we
* can still find a better result in next iterations */
matched_view = list_view;
break;
}
}
if ((!matched_view || matched_by_name) && local_name && local_name[0] != '\0')
{
char *list_name = bamf_view_get_name (list_view);
if (g_strcmp0 (local_name, list_name) == 0)
{
if (!matched_by_name)
{
matched_view = list_view;
matched_by_name = TRUE;
}
else
{
/* We have already matched an app by its name, this
* means that there are two apps with the same name.
* It's safer to ignore both, then. */
matched_view = NULL;
}
}
g_free (list_name);
}
}
}
g_free (local_name);
}
else if (BAMF_IS_WINDOW (view))
{
guint32 local_xid = bamf_window_get_xid (BAMF_WINDOW (view));
for (l = factory->priv->allocated_views; l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
if (!bamf_view_is_closed (l->data))
continue;
BamfView *list_view = BAMF_VIEW (l->data);
BamfWindow *list_win = BAMF_WINDOW (l->data);
guint32 list_xid = bamf_window_get_xid (list_win);
/* We try to match windows by xid */
if (local_xid != 0 && local_xid == list_xid)
{
matched_view = list_view;
break;
}
}
}
if (matched_view)
{
if (view)
{
/* We don't need anymore the view we've just created, let's forget it */
g_object_unref (view);
}
/* If we are here, we're pretty sure that the view is not in the
* open_views, hash-table (since it has been closed) so we can safely
* re-register it here again. */
view = matched_view;
_bamf_view_set_path (view, path);
bamf_factory_register_view (factory, view, path);
}
else if (view)
{
/* It's the first time we register this view, we also have to track it, then */
bamf_factory_track_view (factory, view);
bamf_factory_register_view (factory, view, path);
}
return view;
}
BamfFactory *
_bamf_factory_get_default (void)
{
if (BAMF_IS_FACTORY (static_factory))
return static_factory;
static_factory = (BamfFactory *) g_object_new (BAMF_TYPE_FACTORY, NULL);
return static_factory;
}
./lib/libbamf/bamf-view-private.h 0000644 0000156 0000165 00000003402 12704153435 016740 0 ustar jenkins jenkins /*
* Copyright (C) 2010-2013 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
* Marco Trevisan (Treviño)
*
*/
#ifndef _BAMF_VIEW_PRIVATE_H_
#define _BAMF_VIEW_PRIVATE_H_
#include
#include "bamf-application.h"
#include "bamf-tab.h"
#include "bamf-view.h"
#include "bamf-window.h"
#define CANCELLABLE(view) _bamf_view_get_cancellable (BAMF_VIEW (view))
BamfApplication * bamf_application_new (const char *path);
BamfApplication * bamf_application_new_favorite (const char *favorite_path);
BamfTab * bamf_tab_new (const char *path);
BamfWindow * bamf_window_new (const char *path);
void _bamf_view_set_path (BamfView *view, const char *dbus_path);
const char * _bamf_view_get_path (BamfView *view);
gboolean _bamf_view_remote_ready (BamfView *view);
void _bamf_view_reset_flags (BamfView *view);
void _bamf_view_set_cached_name (BamfView *view, const char *name);
void _bamf_view_set_cached_icon (BamfView *view, const char *icon);
void _bamf_view_set_closed (BamfView *view, gboolean closed);
GCancellable * _bamf_view_get_cancellable (BamfView *view);
#endif
./lib/libbamf/bamf-application.c 0000644 0000156 0000165 00000053170 12704153435 016623 0 ustar jenkins jenkins /*
* Copyright 2010-2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
/**
* SECTION:bamf-application
* @short_description: The base class for all applications
*
* #BamfApplication is the base class that all applications need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-application.h"
#include "bamf-window.h"
#include "bamf-factory.h"
#include "bamf-application-private.h"
#include "bamf-view-private.h"
#include
#include
G_DEFINE_TYPE (BamfApplication, bamf_application, BAMF_TYPE_VIEW);
#define BAMF_APPLICATION_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_APPLICATION, BamfApplicationPrivate))
enum
{
DESKTOP_FILE_UPDATED,
WINDOW_ADDED,
WINDOW_REMOVED,
LAST_SIGNAL,
};
static guint application_signals[LAST_SIGNAL] = { 0 };
struct _BamfApplicationPrivate
{
BamfDBusItemApplication *proxy;
gchar *application_type;
gchar *desktop_file;
GList *cached_xids;
gchar **cached_mimes;
int show_stubs;
};
/**
* bamf_application_get_supported_mime_types:
* @application: a #BamfApplication
*
* Returns: (transfer full) (array zero-terminated=1): A string array containing the supported mime-types.
*/
gchar **
bamf_application_get_supported_mime_types (BamfApplication *application)
{
BamfApplicationPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
priv = application->priv;
if (priv->cached_mimes)
return g_strdupv (priv->cached_mimes);
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return NULL;
if (!_bamf_dbus_item_application_call_supported_mime_types_sync (priv->proxy,
&priv->cached_mimes,
CANCELLABLE (application),
&error))
{
priv->cached_mimes = NULL;
g_warning ("Failed to fetch mimes: %s", error ? error->message : "");
g_error_free (error);
}
return g_strdupv (priv->cached_mimes);
}
/**
* bamf_application_get_desktop_file:
* @application: a #BamfApplication
*
* Used to fetch the path to the .desktop file associated with the passed application. If
* none exists, the result is NULL.
*
* Returns: A string representing the path to the desktop file.
*/
const gchar *
bamf_application_get_desktop_file (BamfApplication *application)
{
BamfApplicationPrivate *priv;
gchar *file;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
priv = application->priv;
if (priv->desktop_file)
return priv->desktop_file;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return NULL;
if (!_bamf_dbus_item_application_call_desktop_file_sync (priv->proxy, &file,
CANCELLABLE (application),
&error))
{
g_warning ("Failed to fetch path: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (file && file[0] == '\0')
{
g_free (file);
file = NULL;
}
priv->desktop_file = file;
return file;
}
/**
* bamf_application_get_application_menu:
* @application: a #BamfApplication
* @name: (out): the bus name
* @object_path: (out): the object path
*
* Used to fetch the bus name and the object path of the remote application menu.
*
* Deprecated: 0.5.0
* Returns: %TRUE if found, %FALSE otherwise.
*/
gboolean
bamf_application_get_application_menu (BamfApplication *application,
gchar **name,
gchar **object_path)
{
BamfApplicationPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
g_return_val_if_fail (name != NULL && object_path != NULL, FALSE);
priv = application->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return FALSE;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!_bamf_dbus_item_application_call_application_menu_sync (priv->proxy, name,
object_path,
CANCELLABLE (application),
&error))
G_GNUC_END_IGNORE_DEPRECATIONS
{
*name = NULL;
*object_path = NULL;
g_warning ("Failed to fetch application menu path: %s", error ? error->message : "");
g_error_free (error);
return FALSE;
}
return TRUE;
}
/**
* bamf_application_get_applicaton_type:
* @application: a #BamfApplication
*
* Used to determine what type of application a .desktop file represents. Current values are:
* "system" : A normal application, like firefox or evolution
* "web" : A web application, like facebook or twitter
*
* Returns: A string
*/
const gchar *
bamf_application_get_application_type (BamfApplication *application)
{
BamfApplicationPrivate *priv;
gchar *type;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
priv = application->priv;
if (priv->application_type)
return priv->application_type;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return NULL;
if (!_bamf_dbus_item_application_call_application_type_sync (priv->proxy, &type,
CANCELLABLE (application),
&error))
{
g_warning ("Failed to fetch path: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
priv->application_type = type;
return type;
}
/**
* bamf_application_get_xids:
* @application: a #BamfApplication
*
* Used to fetch all #BamfWindow's xids associated with the passed #BamfApplication.
*
* Returns: (element-type guint32) (transfer full): An array of xids.
*/
GArray *
bamf_application_get_xids (BamfApplication *application)
{
BamfApplicationPrivate *priv;
GVariantIter *iter;
GVariant *xids_variant;
GArray *xids;
GList *children, *l;
guint32 xid;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
priv = application->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return NULL;
children = bamf_view_peek_children (BAMF_VIEW (application));
if (children)
{
xids = g_array_new (FALSE, TRUE, sizeof (guint32));
for (l = children; l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
g_array_append_val (xids, xid);
}
return xids;
}
if (!_bamf_dbus_item_application_call_xids_sync (priv->proxy, &xids_variant,
CANCELLABLE (application), &error))
{
g_warning ("Failed to fetch xids: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
g_return_val_if_fail (xids_variant, NULL);
g_return_val_if_fail (g_variant_type_equal (g_variant_get_type (xids_variant),
G_VARIANT_TYPE ("au")), NULL);
xids = g_array_new (FALSE, TRUE, sizeof (guint32));
g_variant_get (xids_variant, "au", &iter);
while (g_variant_iter_loop (iter, "u", &xid))
{
g_array_append_val (xids, xid);
}
g_variant_iter_free (iter);
g_variant_unref (xids_variant);
return xids;
}
/**
* bamf_application_get_windows:
* @application: a #BamfApplication
*
* Used to fetch all #BamfWindow's associated with the passed #BamfApplication.
*
* Returns: (element-type Bamf.Window) (transfer container): A list of #BamfWindow's.
*/
GList *
bamf_application_get_windows (BamfApplication *application)
{
GList *children, *l, *next;
BamfView *view;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
children = bamf_view_get_children (BAMF_VIEW (application));
l = children;
while (l != NULL)
{
view = l->data;
next = l->next;
if (!BAMF_IS_WINDOW (view))
{
children = g_list_delete_link (children, l);
}
l = next;
}
return children;
}
/**
* bamf_application_get_window_for_xid:
* @application: a #BamfApplication
* @xid: an X11 Window ID
*
* Used to fetch the application contains a Window with given @xid.
*
* Since: 0.5.2
* Returns: (transfer none): a #BamfWindow for the passed @xid or %NULL if not found.
*/
BamfWindow *
bamf_application_get_window_for_xid (BamfApplication *application,
guint32 xid)
{
GList *l;
BamfWindow *window;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
for (l = bamf_view_peek_children (BAMF_VIEW (application)); l; l = l->next)
{
if (BAMF_IS_WINDOW (l->data))
{
window = BAMF_WINDOW (l->data);
if (bamf_window_get_xid (window) == xid)
return window;
}
}
return NULL;
}
/**
* bamf_application_get_show_menu_stubs:
* @application: a #BamfApplication
*
* Used to discover whether the application wants menu stubs shown.
*
* Returns: Whether the stubs should be shown.
*/
gboolean
bamf_application_get_show_menu_stubs (BamfApplication * application)
{
BamfApplicationPrivate *priv;
GError *error = NULL;
gboolean result;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), TRUE);
priv = application->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return TRUE;
if (priv->show_stubs == -1)
{
if (!_bamf_dbus_item_application_call_show_stubs_sync (priv->proxy, &result,
CANCELLABLE (application),
&error))
{
g_warning ("Failed to fetch show_stubs: %s", error ? error->message : "");
g_error_free (error);
return TRUE;
}
if (result)
priv->show_stubs = 1;
else
priv->show_stubs = 0;
}
return priv->show_stubs;
}
static BamfClickBehavior
bamf_application_get_click_suggestion (BamfView *view)
{
if (!bamf_view_is_running (view))
return BAMF_CLICK_BEHAVIOR_OPEN;
return 0;
}
/**
* bamf_application_get_focusable_child:
* @application: a #BamfApplication
*
* Returns: (transfer none): The focusable child for this application.
*/
BamfView *
bamf_application_get_focusable_child (BamfApplication *application)
{
BamfApplicationPrivate *priv;
BamfView *ret;
gchar *path;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
priv = application->priv;
if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
return NULL;
if (!_bamf_dbus_item_application_call_focusable_child_sync (priv->proxy, &path,
CANCELLABLE (application),
&error))
{
g_warning ("Failed to fetch focusable child: %s", error ? error->message : "");
g_error_free (error);
return NULL;
}
ret = _bamf_factory_view_for_path (_bamf_factory_get_default (), path);
g_free (path);
return ret;
}
static void
bamf_application_on_desktop_file_updated (BamfDBusItemApplication *proxy, const char *desktop_file, BamfApplication *self)
{
g_free (self->priv->desktop_file);
self->priv->desktop_file = g_strdup (desktop_file);
g_signal_emit (self, application_signals[DESKTOP_FILE_UPDATED], 0, desktop_file);
}
static void
bamf_application_on_child_added (BamfApplication *self, BamfView *view)
{
if (BAMF_IS_WINDOW (view))
{
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
if (!g_list_find (self->priv->cached_xids, GUINT_TO_POINTER (xid)))
{
self->priv->cached_xids = g_list_prepend (self->priv->cached_xids, GUINT_TO_POINTER (xid));
}
g_signal_emit (G_OBJECT (self), application_signals[WINDOW_ADDED], 0, view);
}
}
static void
bamf_application_on_child_removed (BamfApplication *self, BamfView *view)
{
if (BAMF_IS_WINDOW (view))
{
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
self->priv->cached_xids = g_list_remove (self->priv->cached_xids, GUINT_TO_POINTER (xid));
g_signal_emit (G_OBJECT (self), application_signals[WINDOW_REMOVED], 0, view);
}
}
GList *
_bamf_application_get_cached_xids (BamfApplication *self)
{
g_return_val_if_fail (BAMF_IS_APPLICATION (self), NULL);
return self->priv->cached_xids;
}
static void
bamf_application_on_supported_mime_types_changed (BamfDBusItemApplication *proxy, const gchar *const *mimes, BamfApplication *self)
{
if (self->priv->cached_mimes)
g_strfreev (self->priv->cached_mimes);
self->priv->cached_mimes = g_strdupv ((gchar**)mimes);
}
static void
bamf_application_unset_proxy (BamfApplication* self)
{
BamfApplicationPrivate *priv;
g_return_if_fail (BAMF_IS_APPLICATION (self));
priv = self->priv;
if (G_IS_DBUS_PROXY (priv->proxy))
{
g_signal_handlers_disconnect_by_data (priv->proxy, self);
g_object_unref (priv->proxy);
priv->proxy = NULL;
}
}
static void
bamf_application_dispose (GObject *object)
{
BamfApplication *self;
BamfApplicationPrivate *priv;
self = BAMF_APPLICATION (object);
priv = self->priv;
if (priv->application_type)
{
g_free (priv->application_type);
priv->application_type = NULL;
}
if (priv->desktop_file)
{
g_free (priv->desktop_file);
priv->desktop_file = NULL;
}
if (priv->cached_xids)
{
g_list_free (priv->cached_xids);
priv->cached_xids = NULL;
}
if (priv->cached_mimes)
{
g_strfreev (priv->cached_mimes);
priv->cached_mimes = NULL;
}
bamf_application_unset_proxy (self);
if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)
G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);
}
static void
bamf_application_set_path (BamfView *view, const char *path)
{
BamfApplication *self;
BamfApplicationPrivate *priv;
GError *error = NULL;
self = BAMF_APPLICATION (view);
priv = self->priv;
bamf_application_unset_proxy (self);
priv->proxy = _bamf_dbus_item_application_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
path, CANCELLABLE (view),
&error);
if (!G_IS_DBUS_PROXY (priv->proxy))
{
g_critical ("Unable to get %s application: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");
g_clear_error (&error);
return;
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
g_signal_connect (priv->proxy, "desktop-file-updated",
G_CALLBACK (bamf_application_on_desktop_file_updated), view);
g_signal_connect (priv->proxy, "supported-mime-types-changed",
G_CALLBACK (bamf_application_on_supported_mime_types_changed), view);
GList *children, *l;
children = bamf_view_peek_children (view);
if (priv->cached_xids)
{
g_list_free (priv->cached_xids);
priv->cached_xids = NULL;
}
for (l = children; l; l = l->next)
{
if (!BAMF_IS_WINDOW (l->data))
continue;
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
priv->cached_xids = g_list_prepend (priv->cached_xids, GUINT_TO_POINTER (xid));
}
}
static void
bamf_application_set_sticky (BamfView *view, gboolean sticky)
{
BamfApplication *self = BAMF_APPLICATION (view);
if (sticky)
{
bamf_application_get_desktop_file (self);
bamf_application_get_application_type (self);
/* When setting the application sticky, we need to cache the relevant values */
if (!self->priv->cached_mimes)
{
gchar **tmp_mimes = bamf_application_get_supported_mime_types (self);
g_strfreev (tmp_mimes);
}
gchar *tmp;
tmp = bamf_view_get_icon (view);
g_free (tmp);
tmp = bamf_view_get_name (view);
g_free (tmp);
}
}
static void
bamf_application_load_data_from_file (BamfApplication *self, GKeyFile * keyfile)
{
GDesktopAppInfo *desktop_info;
GIcon *gicon;
char *fullname;
char *name;
char *icon;
g_return_if_fail (keyfile);
desktop_info = g_desktop_app_info_new_from_keyfile (keyfile);
g_return_if_fail (G_IS_DESKTOP_APP_INFO (desktop_info));
name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
/* Grab the better name if its available */
fullname = g_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_FULLNAME, NULL, NULL);
if (fullname && fullname[0] == '\0')
{
g_free (fullname);
fullname = NULL;
}
if (fullname)
{
g_free (name);
name = fullname;
}
_bamf_view_set_cached_name (BAMF_VIEW (self), name);
gicon = g_app_info_get_icon (G_APP_INFO (desktop_info));
icon = gicon ? g_icon_to_string (gicon) : NULL;
if (!icon)
icon = g_strdup (BAMF_APPLICATION_DEFAULT_ICON);
_bamf_view_set_cached_icon (BAMF_VIEW (self), icon);
self->priv->cached_mimes = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL, NULL);
self->priv->application_type = g_strdup ("system");
g_free (icon);
g_free (name);
g_key_file_free (keyfile);
g_object_unref (desktop_info);
}
static void
bamf_application_class_init (BamfApplicationClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
obj_class->dispose = bamf_application_dispose;
view_class->set_path = bamf_application_set_path;
view_class->set_sticky = bamf_application_set_sticky;
view_class->click_behavior = bamf_application_get_click_suggestion;
g_type_class_add_private (obj_class, sizeof (BamfApplicationPrivate));
application_signals [DESKTOP_FILE_UPDATED] =
g_signal_new (BAMF_APPLICATION_SIGNAL_DESKTOP_FILE_UPDATED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
application_signals [WINDOW_ADDED] =
g_signal_new (BAMF_APPLICATION_SIGNAL_WINDOW_ADDED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_WINDOW);
application_signals [WINDOW_REMOVED] =
g_signal_new (BAMF_APPLICATION_SIGNAL_WINDOW_REMOVED,
G_OBJECT_CLASS_TYPE (klass),
0,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_WINDOW);
}
static void
bamf_application_init (BamfApplication *self)
{
BamfApplicationPrivate *priv;
priv = self->priv = BAMF_APPLICATION_GET_PRIVATE (self);
priv->show_stubs = -1;
g_signal_connect (self, "child-added", G_CALLBACK (bamf_application_on_child_added), NULL);
g_signal_connect (self, "child-removed", G_CALLBACK (bamf_application_on_child_removed), NULL);
}
BamfApplication *
bamf_application_new (const char * path)
{
BamfApplication *self;
self = g_object_new (BAMF_TYPE_APPLICATION, NULL);
_bamf_view_set_path (BAMF_VIEW (self), path);
return self;
}
BamfApplication *
bamf_application_new_favorite (const char * favorite_path)
{
BamfApplication *self;
GKeyFile *desktop_keyfile;
gchar *type;
gboolean supported = FALSE;
g_return_val_if_fail (favorite_path, NULL);
// check that we support this kind of desktop file
desktop_keyfile = g_key_file_new ();
if (g_key_file_load_from_file (desktop_keyfile, favorite_path, G_KEY_FILE_NONE, NULL))
{
type = g_key_file_get_string (desktop_keyfile, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
if (g_strcmp0 (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) == 0)
supported = TRUE;
g_free (type);
}
if (!supported)
{
g_key_file_free (desktop_keyfile);
return NULL;
}
self = g_object_new (BAMF_TYPE_APPLICATION, NULL);
self->priv->desktop_file = g_strdup (favorite_path);
bamf_application_load_data_from_file (self, desktop_keyfile);
return self;
}
./lib/libbamf/bamf-control.c 0000644 0000156 0000165 00000012643 12704153435 016000 0 ustar jenkins jenkins /*
* Copyright 2010-2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
/**
* SECTION:bamf-control
* @short_description: The base class for all controls
*
* #BamfControl is the base class that all controls need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-control.h"
#include "bamf-view-private.h"
G_DEFINE_TYPE (BamfControl, bamf_control, G_TYPE_OBJECT);
#define BAMF_CONTROL_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_CONTROL, BamfControlPrivate))
struct _BamfControlPrivate
{
BamfDBusControl *proxy;
};
/* Globals */
static BamfControl * default_control = NULL;
/* Forwards */
/*
* GObject stuff
*/
static void
bamf_control_dispose (GObject *object)
{
BamfControl *self = BAMF_CONTROL (object);
if (self->priv->proxy)
{
g_object_unref (self->priv->proxy);
self->priv->proxy = NULL;
}
G_OBJECT_CLASS (bamf_control_parent_class)->dispose (object);
}
static void
bamf_control_finalize (GObject *object)
{
default_control = NULL;
G_OBJECT_CLASS (bamf_control_parent_class)->finalize (object);
}
static void
bamf_control_class_init (BamfControlClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
obj_class->dispose = bamf_control_dispose;
obj_class->finalize = bamf_control_finalize;
g_type_class_add_private (obj_class, sizeof (BamfControlPrivate));
obj_class->dispose = bamf_control_dispose;
}
static void
bamf_control_init (BamfControl *self)
{
BamfControlPrivate *priv;
GError *error = NULL;
priv = self->priv = BAMF_CONTROL_GET_PRIVATE (self);
priv->proxy = _bamf_dbus_control_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
BAMF_DBUS_CONTROL_PATH,
NULL, &error);
if (error)
{
g_error ("Unable to get "BAMF_DBUS_CONTROL_PATH" controller: %s", error->message);
g_error_free (error);
return;
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
}
/**
* bamf_control_get_default:
*
* Returns: (transfer full): The default #BamfControl reference.
*/
BamfControl *
bamf_control_get_default (void)
{
if (BAMF_IS_CONTROL (default_control))
return g_object_ref (default_control);
default_control = g_object_new (BAMF_TYPE_CONTROL, NULL);
return default_control;
}
void
bamf_control_insert_desktop_file (BamfControl *control, const gchar *desktop_file)
{
BamfControlPrivate *priv;
GError *error = NULL;
g_return_if_fail (BAMF_IS_CONTROL (control));
priv = control->priv;
if (!_bamf_dbus_control_call_insert_desktop_file_sync (priv->proxy, desktop_file,
NULL, &error))
{
g_warning ("Failed to insert desktop file: %s", error->message);
g_error_free (error);
}
}
void
bamf_control_create_local_desktop_file (BamfControl *control, BamfApplication *app)
{
BamfControlPrivate *priv;
const gchar *app_path;
GError *error = NULL;
g_return_if_fail (BAMF_IS_CONTROL (control));
g_return_if_fail (BAMF_IS_APPLICATION (app));
priv = control->priv;
app_path = _bamf_view_get_path (BAMF_VIEW (app));
if (!app_path)
return;
if (!_bamf_dbus_control_call_create_local_desktop_file_sync (priv->proxy, app_path,
NULL, &error))
{
g_warning ("Failed to create local desktop file: %s", error->message);
g_error_free (error);
}
}
void
bamf_control_register_application_for_pid (BamfControl *control,
const gchar *desktop_file,
gint32 pid)
{
BamfControlPrivate *priv;
GError *error = NULL;
g_return_if_fail (BAMF_IS_CONTROL (control));
priv = control->priv;
if (!_bamf_dbus_control_call_register_application_for_pid_sync (priv->proxy,
desktop_file,
pid, NULL,
&error))
{
g_warning ("Failed to register application: %s", error->message);
g_error_free (error);
}
}
./lib/libbamf/bamf-view.h 0000644 0000156 0000165 00000013104 12704153435 015270 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_VIEW_H_
#define _BAMF_VIEW_H_
#include
G_BEGIN_DECLS
#define BAMF_TYPE_VIEW (bamf_view_get_type ())
#define BAMF_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_VIEW, BamfView))
#define BAMF_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_VIEW, BamfViewClass))
#define BAMF_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_VIEW))
#define BAMF_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_VIEW))
#define BAMF_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_VIEW, BamfViewClass))
#define BAMF_VIEW_SIGNAL_ACTIVE_CHANGED "active-changed"
#define BAMF_VIEW_SIGNAL_RUNNING_CHANGED "running-changed"
#define BAMF_VIEW_SIGNAL_STARTING_CHANGED "starting-changed"
#define BAMF_VIEW_SIGNAL_URGENT_CHANGED "urgent-changed"
#define BAMF_VIEW_SIGNAL_USER_VISIBLE_CHANGED "user-visible-changed"
#define BAMF_VIEW_SIGNAL_NAME_CHANGED "name-changed"
#define BAMF_VIEW_SIGNAL_ICON_CHANGED "icon-changed"
#define BAMF_VIEW_SIGNAL_CHILD_ADDED "child-added"
#define BAMF_VIEW_SIGNAL_CHILD_REMOVED "child-removed"
#define BAMF_VIEW_SIGNAL_CHILD_MOVED "child-moved"
#define BAMF_VIEW_SIGNAL_CLOSED "closed"
typedef enum
{
BAMF_CLICK_BEHAVIOR_NONE,
BAMF_CLICK_BEHAVIOR_OPEN,
BAMF_CLICK_BEHAVIOR_FOCUS,
BAMF_CLICK_BEHAVIOR_FOCUS_ALL,
BAMF_CLICK_BEHAVIOR_MINIMIZE,
BAMF_CLICK_BEHAVIOR_RESTORE,
BAMF_CLICK_BEHAVIOR_RESTORE_ALL,
BAMF_CLICK_BEHAVIOR_PICKER,
} BamfClickBehavior;
typedef struct _BamfView BamfView;
typedef struct _BamfViewClass BamfViewClass;
typedef struct _BamfViewPrivate BamfViewPrivate;
struct _BamfView
{
GInitiallyUnowned parent;
BamfViewPrivate *priv;
};
struct _BamfViewClass
{
GInitiallyUnownedClass parent_class;
GList * (*get_children) (BamfView *view);
gboolean (*is_active) (BamfView *view);
gboolean (*is_running) (BamfView *view);
gboolean (*is_urgent) (BamfView *view);
gboolean (*is_user_visible) (BamfView *view);
gchar * (*get_name) (BamfView *view);
gchar * (*get_icon) (BamfView *view);
const gchar * (*view_type) (BamfView *view);
void (*set_path) (BamfView *view, const gchar *path);
void (*set_sticky) (BamfView *view, gboolean value);
BamfClickBehavior (*click_behavior) (BamfView *view);
/*< signals >*/
void (*active_changed) (BamfView *view, gboolean active);
void (*closed) (BamfView *view);
void (*child_added) (BamfView *view, BamfView *child);
void (*child_removed) (BamfView *view, BamfView *child);
void (*running_changed) (BamfView *view, gboolean running);
void (*urgent_changed) (BamfView *view, gboolean urgent);
void (*user_visible_changed) (BamfView *view, gboolean user_visible);
void (*name_changed) (BamfView *view, gchar* old_name, gchar* new_name);
void (*icon_changed) (BamfView *view, gchar* icon);
void (*child_moved) (BamfView *view, BamfView *child);
gboolean (*is_starting) (BamfView *view);
void (*starting_changed) (BamfView *view, gboolean starting);
/*< private >*/
void (*_view_padding1) (void);
};
GType bamf_view_get_type (void) G_GNUC_CONST;
GList * bamf_view_get_children (BamfView *view);
GList * bamf_view_peek_children (BamfView *view);
gboolean bamf_view_has_child (BamfView *view, BamfView *child);
gboolean bamf_view_is_closed (BamfView *view);
gboolean bamf_view_is_active (BamfView *view);
gboolean bamf_view_is_starting (BamfView *view);
gboolean bamf_view_is_running (BamfView *view);
gboolean bamf_view_is_urgent (BamfView *view);
gboolean bamf_view_is_user_visible (BamfView *view);
gchar * bamf_view_get_name (BamfView *view);
gchar * bamf_view_get_icon (BamfView *view);
const gchar * bamf_view_get_view_type (BamfView *view);
void bamf_view_set_sticky (BamfView *view, gboolean value);
gboolean bamf_view_is_sticky (BamfView *view);
/* Deprecated symbols */
G_GNUC_DEPRECATED
BamfClickBehavior bamf_view_get_click_suggestion (BamfView *view);
G_GNUC_DEPRECATED_FOR (bamf_view_user_visible)
gboolean bamf_view_user_visible (BamfView *view);
G_END_DECLS
#endif
./lib/libbamf/bamf-tab.c 0000644 0000156 0000165 00000024034 12704153435 015063 0 ustar jenkins jenkins /*
* Copyright 2010-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
Robert Carr
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#include
#include "bamf-tab.h"
#include "bamf-view-private.h"
#define BAMF_TAB_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE (object, BAMF_TYPE_TAB, BamfTabPrivate))
enum
{
PROP_0,
PROP_LOCATION,
PROP_DESKTOP_ID,
PROP_XID,
PROP_IS_FOREGROUND_TAB
};
struct _BamfTabPrivate
{
BamfDBusItemTab *proxy;
};
static void bamf_tab_unset_proxy (BamfTab *self);
G_DEFINE_TYPE (BamfTab, bamf_tab, BAMF_TYPE_VIEW);
static void
on_proxy_property_change (GObject *gobject, GParamSpec *pspec, gpointer user_data)
{
BamfTab *self = BAMF_TAB (user_data);
if (g_object_class_find_property (G_OBJECT_GET_CLASS (self), pspec->name))
g_object_notify (G_OBJECT (self), pspec->name);
}
static void
bamf_tab_set_path (BamfView *view, const gchar *path)
{
BamfTab *self;
BamfTabPrivate *priv;
GError *error = NULL;
self = BAMF_TAB (view);
priv = self->priv;
bamf_tab_unset_proxy (self);
priv->proxy = _bamf_dbus_item_tab_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
path, CANCELLABLE (view),
&error);
if (!G_IS_DBUS_PROXY (priv->proxy))
{
g_error ("Unable to get %s tab: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");
g_error_free (error);
return;
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
g_signal_connect (priv->proxy, "notify", G_CALLBACK (on_proxy_property_change), self);
}
static void
bamf_tab_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
BamfTab *self;
self = BAMF_TAB (object);
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
return;
}
switch (property_id)
{
case PROP_LOCATION:
g_value_set_string (value, _bamf_dbus_item_tab_get_location (self->priv->proxy));
break;
case PROP_DESKTOP_ID:
g_value_set_string (value, _bamf_dbus_item_tab_get_desktop_id (self->priv->proxy));
break;
case PROP_XID:
g_value_set_uint64 (value, _bamf_dbus_item_tab_get_xid (self->priv->proxy));
break;
case PROP_IS_FOREGROUND_TAB:
g_value_set_boolean (value, _bamf_dbus_item_tab_get_is_foreground_tab (self->priv->proxy));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
bamf_tab_unset_proxy (BamfTab *self)
{
if (!G_IS_DBUS_PROXY (self->priv->proxy))
return;
g_signal_handlers_disconnect_by_data (self->priv->proxy, self);
g_object_unref (self->priv->proxy);
self->priv->proxy = NULL;
}
static void
bamf_tab_dispose (GObject *object)
{
BamfTab *self;
self = BAMF_TAB (object);
bamf_tab_unset_proxy (self);
if (G_OBJECT_CLASS (bamf_tab_parent_class)->dispose)
G_OBJECT_CLASS (bamf_tab_parent_class)->dispose (object);
}
static void
bamf_tab_class_init (BamfTabClass *klass)
{
GParamSpec *pspec;
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);
obj_class->dispose = bamf_tab_dispose;
obj_class->get_property = bamf_tab_get_property;
view_class->set_path = bamf_tab_set_path;
pspec = g_param_spec_string("location", "Location", "The Current location of the remote Tab",
NULL, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_LOCATION, pspec);
pspec = g_param_spec_string("desktop-id", "Desktop Name", "The Desktop ID assosciated with the application hosted in the remote Tab",
NULL, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_DESKTOP_ID, pspec);
pspec = g_param_spec_uint64("xid", "xid", "XID for the toplevel window containing the remote Tab",
0, G_MAXUINT64, 0, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_XID, pspec);
pspec = g_param_spec_boolean("is-foreground-tab", "Foreground tab", "Whether the tab is the foreground tab in it's toplevel container",
FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_IS_FOREGROUND_TAB, pspec);
g_type_class_add_private (obj_class, sizeof(BamfTabPrivate));
}
static void
bamf_tab_init (BamfTab *self)
{
self->priv = BAMF_TAB_GET_PRIVATE (self);
}
BamfTab *
bamf_tab_new (const gchar *path)
{
BamfTab *self;
self = g_object_new (BAMF_TYPE_TAB, NULL);
_bamf_view_set_path (BAMF_VIEW (self), path);
return self;
}
/**
* bamf_tab_raise:
* @self: A #BamfTab.
*
* Selects the @self tab in the parent window.
*
* Returns: %TRUE if success, %FALSE otherwise.
*/
gboolean
bamf_tab_raise (BamfTab *self)
{
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_TAB (self), FALSE);
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return FALSE;
if (!_bamf_dbus_item_tab_call_raise_sync (self->priv->proxy, CANCELLABLE (self), &error))
{
g_warning ("Failed to invoke Raise method: %s", error ? error->message : "");
g_error_free (error);
return FALSE;
}
return TRUE;
}
/**
* bamf_tab_close:
* @self: A #BamfTab.
*
* Closes the selected @self tab.
*
* Returns: %TRUE if success, %FALSE otherwise.
*/
gboolean
bamf_tab_close (BamfTab *self)
{
GError *error;
g_return_val_if_fail (BAMF_IS_TAB (self), FALSE);
if (!_bamf_view_remote_ready (BAMF_VIEW (self)))
return FALSE;
error = NULL;
if (!_bamf_dbus_item_tab_call_close_sync (self->priv->proxy, CANCELLABLE (self), &error))
{
g_warning ("Failed to invoke Close method: %s", error->message);
g_error_free (error);
return FALSE;
}
return TRUE;
}
typedef struct _BamfTabPreviewRequestData
{
BamfTab *self;
BamfTabPreviewReadyCallback callback;
gpointer user_data;
} BamfTabPreviewRequestData;
static void
on_preview_ready (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
BamfTab *self;
BamfTabPreviewRequestData *data;
gchar *preview_data = NULL;
GError *error = NULL;
data = user_data;
self = data->self;
if (_bamf_dbus_item_tab_call_request_preview_finish (self->priv->proxy, &preview_data, res, &error))
{
data->callback (self, preview_data, data->user_data);
g_free (preview_data);
}
else
{
data->callback (self, NULL, data->user_data);
g_warning ("Error requesting BamfTab preview: %s", error ? error->message : "");
g_error_free (error);
}
g_free (data);
}
/**
* bamf_tab_request_preview:
* @self: a #BamfTab
* @callback: (closure) (scope async): a callback function to call when the result is ready
* @user_data: (closure) (allow-none): data to be sent to the callback.
*/
void
bamf_tab_request_preview (BamfTab *self, BamfTabPreviewReadyCallback callback, gpointer user_data)
{
BamfTabPreviewRequestData *data;
g_return_if_fail (BAMF_IS_TAB (self));
g_return_if_fail (callback != NULL);
data = g_malloc (sizeof (BamfTabPreviewRequestData));
data->self = self;
data->callback = callback;
data->user_data = user_data;
_bamf_dbus_item_tab_call_request_preview (self->priv->proxy, NULL,
on_preview_ready, data);
}
const gchar *
bamf_tab_get_location (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), NULL);
if (BAMF_TAB_GET_CLASS (self)->get_location)
return BAMF_TAB_GET_CLASS (self)->get_location (self);
return _bamf_dbus_item_tab_get_location (self->priv->proxy);
}
/**
* bamf_tab_get_desktop_name:
* @self: A #BamfTab.
*
* Returns the desktop file for the tab.
*
* Returns: (transfer none): The tab desktop id or %NULL if not set or available. Do not free the returned value, it belongs to @self.
*/
const gchar *
bamf_tab_get_desktop_name (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), NULL);
if (BAMF_TAB_GET_CLASS (self)->get_desktop_name)
return BAMF_TAB_GET_CLASS (self)->get_desktop_name (self);
return _bamf_dbus_item_tab_get_desktop_id (self->priv->proxy);
}
/**
* bamf_tab_get_xid:
* @self: A #BamfTab.
*
* The desktop file for the tab.
*
* Returns: The tab parent window XID id or 0 if not set or available.
*/
guint64
bamf_tab_get_xid (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), 0);
if (BAMF_TAB_GET_CLASS (self)->get_xid)
return BAMF_TAB_GET_CLASS (self)->get_xid (self);
return _bamf_dbus_item_tab_get_xid (self->priv->proxy);
}
/**
* bamf_tab_get_is_foreground_tab:
* @self: A #BamfTab.
*
* Returns: %TRUE if the tab is the active one on parent window XID, %FALSE otherwise.
*/
gboolean
bamf_tab_get_is_foreground_tab (BamfTab *self)
{
g_return_val_if_fail (BAMF_IS_TAB (self), FALSE);
if (BAMF_TAB_GET_CLASS (self)->get_is_foreground_tab)
return BAMF_TAB_GET_CLASS (self)->get_is_foreground_tab (self);
return _bamf_dbus_item_tab_get_is_foreground_tab (self->priv->proxy);
}
./lib/libbamf/bamf-window.h 0000644 0000156 0000165 00000011026 12704153435 015626 0 ustar jenkins jenkins /*
* Copyright 2010-2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef _BAMF_WINDOW_H_
#define _BAMF_WINDOW_H_
#include
#include
#include
G_BEGIN_DECLS
#define BAMF_TYPE_WINDOW (bamf_window_get_type ())
#define BAMF_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
BAMF_TYPE_WINDOW, BamfWindow))
#define BAMF_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
BAMF_TYPE_WINDOW, BamfWindowClass))
#define BAMF_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
BAMF_TYPE_WINDOW))
#define BAMF_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
BAMF_TYPE_WINDOW))
#define BAMF_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
BAMF_TYPE_WINDOW, BamfWindowClass))
#define BAMF_WINDOW_SIGNAL_MONITOR_CHANGED "monitor-changed"
#define BAMF_WINDOW_SIGNAL_MAXIMIZED_CHANGED "maximized-changed"
typedef struct _BamfWindow BamfWindow;
typedef struct _BamfWindowClass BamfWindowClass;
typedef struct _BamfWindowPrivate BamfWindowPrivate;
struct _BamfWindow
{
BamfView parent;
BamfWindowPrivate *priv;
};
typedef enum
{
BAMF_WINDOW_NORMAL, /* document/app window */
BAMF_WINDOW_DESKTOP, /* desktop background */
BAMF_WINDOW_DOCK, /* panel */
BAMF_WINDOW_DIALOG, /* dialog */
BAMF_WINDOW_TOOLBAR, /* tearoff toolbar */
BAMF_WINDOW_MENU, /* tearoff menu */
BAMF_WINDOW_UTILITY, /* palette/toolbox window */
BAMF_WINDOW_SPLASHSCREEN, /* splash screen */
BAMF_WINDOW_UNKNOWN
} BamfWindowType;
typedef enum
{
BAMF_WINDOW_FLOATING, /* Floating window */
BAMF_WINDOW_HORIZONTAL_MAXIMIZED, /* Horizontally maximized window */
BAMF_WINDOW_VERTICAL_MAXIMIZED, /* Vertically maximized window */
BAMF_WINDOW_MAXIMIZED /* Maximized window */
} BamfWindowMaximizationType;
struct _BamfWindowClass
{
BamfViewClass parent_class;
BamfWindow * (*get_transient) (BamfWindow *self);
BamfWindowType (*get_window_type) (BamfWindow *self);
guint32 (*get_xid) (BamfWindow *self);
guint32 (*get_pid) (BamfWindow *self);
gint (*get_monitor) (BamfWindow *self);
gchar * (*get_utf8_prop) (BamfWindow *self, const char* prop);
BamfWindowMaximizationType (*maximized) (BamfWindow *self);
time_t (*last_active) (BamfWindow *self);
/*< signals >*/
void (*monitor_changed) (BamfWindow *window, gint old_value, gint new_value);
void (*maximized_changed) (BamfWindow *window, gint old_value, gint new_value);
/*< private >*/
void (*_window_padding1) (void);
void (*_window_padding2) (void);
void (*_window_padding3) (void);
void (*_window_padding4) (void);
};
GType bamf_window_get_type (void) G_GNUC_CONST;
BamfWindow * bamf_window_get_transient (BamfWindow *self);
BamfWindowType bamf_window_get_window_type (BamfWindow *self);
guint32 bamf_window_get_xid (BamfWindow *self);
guint32 bamf_window_get_pid (BamfWindow *self);
gint bamf_window_get_monitor (BamfWindow *self);
gchar * bamf_window_get_utf8_prop (BamfWindow *self, const char* prop);
BamfWindowMaximizationType bamf_window_maximized (BamfWindow *self);
time_t bamf_window_last_active (BamfWindow *self);
G_END_DECLS
#endif
./lib/libbamf/bamf-view.c 0000644 0000156 0000165 00000071124 12704153435 015271 0 ustar jenkins jenkins /*
* Copyright 2010-2012 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of either or both of the following licenses:
*
* 1) the GNU Lesser General Public License version 3, as published by the
* Free Software Foundation; and/or
* 2) the GNU Lesser General Public License version 2.1, 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 and version 2.1 along with this program. If not, see
*
*
* Authored by: Jason Smith
* Neil Jagdish Patel
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
/**
* SECTION:bamf-view
* @short_description: The base class for all views
*
* #BamfView is the base class that all views need to derive from.
*/
#if HAVE_CONFIG_H
#include
#endif
#include
#include "bamf-view.h"
#include "bamf-view-private.h"
#include "bamf-factory.h"
#include "bamf-tab.h"
#include "bamf-window.h"
G_DEFINE_TYPE (BamfView, bamf_view, G_TYPE_INITIALLY_UNOWNED);
#define BAMF_VIEW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BAMF_TYPE_VIEW, BamfViewPrivate))
enum
{
ACTIVE_CHANGED,
CLOSED,
CHILD_ADDED,
CHILD_REMOVED,
CHILD_MOVED,
STARTING_CHANGED,
RUNNING_CHANGED,
URGENT_CHANGED,
VISIBLE_CHANGED,
NAME_CHANGED,
ICON_CHANGED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_PATH,
PROP_STARTING,
PROP_RUNNING,
PROP_ACTIVE,
PROP_USER_VISIBLE,
PROP_URGENT,
PROP_LAST
};
static guint view_signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[PROP_LAST] = { 0 };
struct _BamfViewPrivate
{
BamfDBusItemView *proxy;
GCancellable *cancellable;
gchar *type;
gchar *cached_name;
gchar *cached_icon;
GList *cached_children;
gboolean reload_children;
gboolean is_closed;
gboolean sticky;
};
static void bamf_view_unset_proxy (BamfView *self);
/**
* bamf_view_get_children:
* @view: a #BamfView
*
* Note: Makes sever dbus calls the first time this is called on a view. Dbus messaging is reduced afterwards.
*
* Returns: (element-type Bamf.View) (transfer container): Returns a list of #BamfView which must be
* freed after usage. Elements of the list are owned by bamf and should not be unreffed.
*/
GList *
bamf_view_get_children (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
if (BAMF_VIEW_GET_CLASS (view)->get_children)
return BAMF_VIEW_GET_CLASS (view)->get_children (view);
return g_list_copy (bamf_view_peek_children (view));
}
/**
* bamf_view_peek_children:
* @view: a #BamfView
*
* Note: Makes sever dbus calls the first time this is called on a view.
* Dbus messaging is reduced afterwards.
* Since: 0.5.2
* Returns: (element-type Bamf.View) (transfer none): Returns a list of #BamfView which
* is owned by the #BamfView and should not freed or modified after usage.
*/
GList *
bamf_view_peek_children (BamfView *view)
{
char ** children;
int i, len;
GList *results = NULL;
GError *error = NULL;
BamfViewPrivate *priv;
BamfView *child;
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
if (!_bamf_view_remote_ready (view))
return NULL;
priv = view->priv;
if (priv->cached_children || !priv->reload_children)
return priv->cached_children;
if (!_bamf_dbus_item_view_call_children_sync (priv->proxy, &children, CANCELLABLE (view), &error))
{
g_warning ("Unable to fetch children: %s\n", error ? error->message : "");
g_error_free (error);
return NULL;
}
if (!children)
return NULL;
len = g_strv_length (children);
for (i = len-1; i >= 0; --i)
{
child = _bamf_factory_view_for_path (_bamf_factory_get_default (), children[i]);
if (BAMF_IS_VIEW (child))
{
results = g_list_prepend (results, g_object_ref (child));
}
}
if (priv->cached_children)
g_list_free_full (priv->cached_children, g_object_unref);
priv->reload_children = FALSE;
priv->cached_children = results;
return priv->cached_children;
}
/**
* bamf_view_has_child:
* @view: a #BamfView
*
* Returns: %TRUE whether the #BamfView @view has the specified @child.
*/
gboolean
bamf_view_has_child (BamfView *view, BamfView *child)
{
GList *l;
g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
g_return_val_if_fail (BAMF_IS_VIEW (child), FALSE);
for (l = bamf_view_peek_children (view); l; l = l->next)
{
if (l->data == child)
return TRUE;
}
return FALSE;
}
/**
* bamf_view_is_closed:
* @view: a #BamfView
*
* Determines if the view is closed or not.
*/
gboolean
bamf_view_is_closed (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), TRUE);
return view->priv->is_closed;
}
/**
* bamf_view_is_active:
* @view: a #BamfView
*
* Determines if the view is currently active and focused by the user. Useful for an active window indicator.
*/
gboolean
bamf_view_is_active (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
if (BAMF_VIEW_GET_CLASS (view)->is_active)
return BAMF_VIEW_GET_CLASS (view)->is_active (view);
if (!_bamf_view_remote_ready (view))
return FALSE;
return _bamf_dbus_item_view_get_active (view->priv->proxy);
}
/**
* bamf_view_is_user_visible:
* @view: a #BamfView
*
* Returns: a boolean useful for determining if a particular view is "user visible". User visible
* is a concept relating to whether or not a window should be shown in a launcher tasklist.
*
* Since: 0.4.0
*/
gboolean
bamf_view_is_user_visible (BamfView *self)
{
g_return_val_if_fail (BAMF_IS_VIEW (self), FALSE);
if (BAMF_VIEW_GET_CLASS (self)->is_user_visible)
return BAMF_VIEW_GET_CLASS (self)->is_user_visible (self);
if (!_bamf_view_remote_ready (self))
return FALSE;
return _bamf_dbus_item_view_get_user_visible (self->priv->proxy);
}
/**
* bamf_view_user_visible: (skip)
* @view: a #BamfView
*
* Returns: a boolean useful for determining if a particular view is "user visible". User visible
* is a concept relating to whether or not a window should be shown in a launcher tasklist.
*
* Deprecated: 0.4.0
*/
gboolean
bamf_view_user_visible (BamfView *self)
{
return bamf_view_is_user_visible (self);
}
/**
* bamf_view_is_starting:
* @view: a #BamfView
*
* Determines if the view is currently starting. Useful for the startup animation.
*/
gboolean
bamf_view_is_starting (BamfView *self)
{
g_return_val_if_fail (BAMF_IS_VIEW (self), FALSE);
if (BAMF_VIEW_GET_CLASS (self)->is_starting)
return BAMF_VIEW_GET_CLASS (self)->is_starting (self);
if (!_bamf_view_remote_ready (self))
return FALSE;
return _bamf_dbus_item_view_get_starting (self->priv->proxy);
}
/**
* bamf_view_is_running:
* @view: a #BamfView
*
* Determines if the view is currently running. Useful for a running window indicator.
*/
gboolean
bamf_view_is_running (BamfView *self)
{
g_return_val_if_fail (BAMF_IS_VIEW (self), FALSE);
if (BAMF_VIEW_GET_CLASS (self)->is_running)
return BAMF_VIEW_GET_CLASS (self)->is_running (self);
if (!_bamf_view_remote_ready (self))
return FALSE;
return _bamf_dbus_item_view_get_running (self->priv->proxy);
}
/**
* bamf_view_is_urgent:
* @view: a #BamfView
*
* Determines if the view is currently requiring attention. Useful for a running window indicator.
*/
gboolean
bamf_view_is_urgent (BamfView *self)
{
g_return_val_if_fail (BAMF_IS_VIEW (self), FALSE);
if (BAMF_VIEW_GET_CLASS (self)->is_urgent)
return BAMF_VIEW_GET_CLASS (self)->is_urgent (self);
if (!_bamf_view_remote_ready (self))
return FALSE;
return _bamf_dbus_item_view_get_urgent (self->priv->proxy);
}
void
_bamf_view_set_cached_name (BamfView *view, const char *name)
{
g_return_if_fail (BAMF_IS_VIEW (view));
if (!name || g_strcmp0 (name, view->priv->cached_name) == 0)
return;
g_free (view->priv->cached_name);
view->priv->cached_name = NULL;
if (name && name[0] != '\0')
{
view->priv->cached_name = g_strdup (name);
}
}
void
_bamf_view_set_cached_icon (BamfView *view, const char *icon)
{
g_return_if_fail (BAMF_IS_VIEW (view));
if (!icon || g_strcmp0 (icon, view->priv->cached_icon) == 0)
return;
g_free (view->priv->cached_icon);
view->priv->cached_icon = NULL;
if (icon && icon[0] != '\0')
{
view->priv->cached_icon = g_strdup (icon);
}
}
gboolean
bamf_view_is_sticky (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
return view->priv->sticky;
}
void
bamf_view_set_sticky (BamfView *view, gboolean sticky)
{
g_return_if_fail (BAMF_IS_VIEW (view));
if (view->priv->sticky == sticky)
return;
view->priv->sticky = sticky;
if (sticky)
{
g_object_ref_sink (view);
}
else
{
g_object_unref (view);
}
if (BAMF_VIEW_GET_CLASS (view)->set_sticky)
return BAMF_VIEW_GET_CLASS (view)->set_sticky (view, sticky);
}
/**
* bamf_view_get_icon:
* @view: a #BamfView
*
* Gets the icon of a view. This icon is used to visually represent the view.
*/
gchar *
bamf_view_get_icon (BamfView *self)
{
BamfViewPrivate *priv;
g_return_val_if_fail (BAMF_IS_VIEW (self), NULL);
priv = self->priv;
if (BAMF_VIEW_GET_CLASS (self)->get_icon)
return BAMF_VIEW_GET_CLASS (self)->get_icon (self);
if (!_bamf_view_remote_ready (self))
return g_strdup (priv->cached_icon);
return _bamf_dbus_item_view_dup_icon (priv->proxy);
}
/**
* bamf_view_get_name:
* @view: a #BamfView
*
* Gets the name of a view. This name is a short name best used to represent the view with text.
*/
gchar *
bamf_view_get_name (BamfView *self)
{
BamfViewPrivate *priv;
g_return_val_if_fail (BAMF_IS_VIEW (self), NULL);
priv = self->priv;
if (BAMF_VIEW_GET_CLASS (self)->get_name)
return BAMF_VIEW_GET_CLASS (self)->get_name (self);
if (!_bamf_view_remote_ready (self))
return g_strdup (priv->cached_name);
return _bamf_dbus_item_view_dup_name (priv->proxy);
}
gboolean
_bamf_view_remote_ready (BamfView *self)
{
if (BAMF_IS_VIEW (self) && G_IS_DBUS_PROXY (self->priv->proxy))
return !self->priv->is_closed;
return FALSE;
}
/**
* bamf_view_get_view_type: (virtual view_type)
* @view: a #BamfView
*
* The view type of a window is a short string used to represent all views of the same class. These
* descriptions should not be used to do casting as they are not considered stable.
*/
const gchar *
bamf_view_get_view_type (BamfView *self)
{
BamfViewPrivate *priv;
char *type = NULL;
GError *error = NULL;
g_return_val_if_fail (BAMF_IS_VIEW (self), NULL);
priv = self->priv;
if (BAMF_VIEW_GET_CLASS (self)->view_type)
return BAMF_VIEW_GET_CLASS (self)->view_type (self);
if (priv->type)
return priv->type;
if (!_bamf_view_remote_ready (self))
return NULL;
if (!_bamf_dbus_item_view_call_view_type_sync (priv->proxy, &type, CANCELLABLE (self), &error))
{
const gchar *path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (priv->proxy));
g_warning ("Failed to fetch view type at %s: %s", path, error ? error->message : "");
g_error_free (error);
return NULL;
}
priv->type = type;
return type;
}
BamfClickBehavior
bamf_view_get_click_suggestion (BamfView *self)
{
g_return_val_if_fail (BAMF_IS_VIEW (self), BAMF_CLICK_BEHAVIOR_NONE);
if (BAMF_VIEW_GET_CLASS (self)->click_behavior)
return BAMF_VIEW_GET_CLASS (self)->click_behavior (self);
return BAMF_CLICK_BEHAVIOR_NONE;
}
static void
bamf_view_child_xid_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
{
BamfView *self;
self = (BamfView *)user_data;
g_signal_emit (G_OBJECT (self), view_signals[CHILD_MOVED], 0, BAMF_VIEW (object));
g_signal_emit (G_OBJECT (self), view_signals[VISIBLE_CHANGED], 0);
}
static void
bamf_view_on_child_added (BamfDBusItemView *proxy, const char *path, BamfView *self)
{
BamfView *view;
BamfViewPrivate *priv;
view = _bamf_factory_view_for_path (_bamf_factory_get_default (), path);
priv = self->priv;
g_return_if_fail (BAMF_IS_VIEW (view));
if (BAMF_IS_TAB (view))
{
g_signal_connect (view, "notify::xid",
G_CALLBACK (bamf_view_child_xid_changed), self);
}
if (!g_list_find (priv->cached_children, view))
{
g_object_ref (view);
priv->cached_children = g_list_prepend (priv->cached_children, view);
}
g_signal_emit (G_OBJECT (self), view_signals[CHILD_ADDED], 0, view);
}
static void
bamf_view_on_child_removed (BamfDBusItemView *proxy, char *path, BamfView *self)
{
BamfView *view;
BamfViewPrivate *priv;
gboolean was_cached = FALSE;
view = _bamf_factory_view_for_path (_bamf_factory_get_default (), path);
priv = self->priv;
g_return_if_fail (BAMF_IS_VIEW (view));
if (BAMF_IS_TAB (view))
{
g_signal_handlers_disconnect_by_func (view, bamf_view_child_xid_changed, self);
}
if (priv->cached_children)
{
GList *l = g_list_find (priv->cached_children, view);
if (l)
{
priv->cached_children = g_list_delete_link (priv->cached_children, l);
was_cached = TRUE;
}
}
g_signal_emit (G_OBJECT (self), view_signals[CHILD_REMOVED], 0, view);
if (was_cached)
g_object_unref (view);
}
static void
bamf_view_on_name_owner_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
/* This is called when the bamfdaemon is killed / started */
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
if (!name_owner)
{
if (self->priv->cached_children)
{
g_list_free_full (self->priv->cached_children, g_object_unref);
self->priv->reload_children = TRUE;
self->priv->cached_children = NULL;
}
if (self->priv->cached_name)
{
const char *cached_name = self->priv->cached_name;
g_signal_emit (G_OBJECT (self), view_signals[NAME_CHANGED], 0, NULL, cached_name);
}
if (self->priv->cached_icon)
{
const char *cached_icon = self->priv->cached_icon;
g_signal_emit (G_OBJECT (self), view_signals[ICON_CHANGED], 0, cached_icon);
}
_bamf_view_set_closed (self, TRUE);
g_signal_emit (G_OBJECT (self), view_signals[CLOSED], 0);
}
g_free (name_owner);
}
static void
bamf_view_on_active_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
gboolean active = _bamf_dbus_item_view_get_active (proxy);
g_signal_emit (G_OBJECT (self), view_signals[ACTIVE_CHANGED], 0, active);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVE]);
}
static void
bamf_view_on_name_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
const char *new_name = _bamf_dbus_item_view_get_name (proxy);
const char *old_name = self->priv->cached_name;
g_signal_emit (self, view_signals[NAME_CHANGED], 0, old_name, new_name);
_bamf_view_set_cached_name (self, new_name);
}
static void
bamf_view_on_icon_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
const char *icon = _bamf_dbus_item_view_get_icon (proxy);
g_signal_emit (self, view_signals[ICON_CHANGED], 0, icon);
_bamf_view_set_cached_icon (self, icon);
}
static void
bamf_view_on_starting_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
gboolean starting = _bamf_dbus_item_view_get_starting (proxy);
g_signal_emit (G_OBJECT (self), view_signals[STARTING_CHANGED], 0, starting);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STARTING]);
}
static void
bamf_view_on_running_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
gboolean running = _bamf_dbus_item_view_get_running (proxy);
g_signal_emit (G_OBJECT (self), view_signals[RUNNING_CHANGED], 0, running);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RUNNING]);
}
static void
bamf_view_on_urgent_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
gboolean urgent = _bamf_dbus_item_view_get_urgent (proxy);
g_signal_emit (G_OBJECT (self), view_signals[URGENT_CHANGED], 0, urgent);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_URGENT]);
}
static void
bamf_view_on_user_visible_changed (BamfDBusItemView *proxy, GParamSpec *param, BamfView *self)
{
gboolean user_visible = _bamf_dbus_item_view_get_user_visible (proxy);
g_signal_emit (G_OBJECT (self), view_signals[VISIBLE_CHANGED], 0, user_visible);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_VISIBLE]);
}
GCancellable *
_bamf_view_get_cancellable (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
return view->priv->cancellable;
}
void
_bamf_view_set_closed (BamfView *self, gboolean closed)
{
BamfViewPrivate *priv;
g_return_if_fail (BAMF_IS_VIEW (self));
priv = self->priv;
if (priv->is_closed != closed)
{
priv->is_closed = closed;
if (closed)
{
g_cancellable_cancel (priv->cancellable);
g_list_free_full (priv->cached_children, g_object_unref);
priv->cached_children = NULL;
}
else
{
g_cancellable_reset (priv->cancellable);
}
}
}
static void
bamf_view_on_closed (BamfDBusItemView *proxy, BamfView *self)
{
_bamf_view_set_closed (self, TRUE);
g_signal_emit (G_OBJECT (self), view_signals[CLOSED], 0);
}
static void
bamf_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
bamf_view_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
BamfView *self;
self = BAMF_VIEW (object);
switch (property_id)
{
case PROP_PATH:
g_value_set_string (value, bamf_view_is_closed (self) ? NULL : _bamf_view_get_path (self));
break;
case PROP_ACTIVE:
g_value_set_boolean (value, bamf_view_is_active (self));
break;
case PROP_STARTING:
g_value_set_boolean (value, bamf_view_is_starting (self));
break;
case PROP_RUNNING:
g_value_set_boolean (value, bamf_view_is_running (self));
break;
case PROP_URGENT:
g_value_set_boolean (value, bamf_view_is_urgent (self));
break;
case PROP_USER_VISIBLE:
g_value_set_boolean (value, bamf_view_is_user_visible (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
bamf_view_unset_proxy (BamfView *self)
{
BamfViewPrivate *priv;
g_return_if_fail (BAMF_IS_VIEW (self));
priv = self->priv;
if (!priv->proxy)
return;
g_signal_handlers_disconnect_by_data (priv->proxy, self);
g_object_unref (priv->proxy);
priv->proxy = NULL;
}
static void
bamf_view_dispose (GObject *object)
{
BamfView *view;
BamfViewPrivate *priv;
view = BAMF_VIEW (object);
priv = view->priv;
if (priv->cancellable)
{
g_cancellable_cancel (priv->cancellable);
g_object_unref (priv->cancellable);
priv->cancellable = NULL;
}
if (priv->type)
{
g_free (priv->type);
priv->type = NULL;
}
if (priv->cached_icon)
{
g_free (priv->cached_icon);
priv->cached_icon = NULL;
}
if (priv->cached_name)
{
g_free (priv->cached_name);
priv->cached_name = NULL;
}
if (priv->cached_children)
{
g_list_free_full (priv->cached_children, g_object_unref);
priv->cached_children = NULL;
}
bamf_view_unset_proxy (view);
G_OBJECT_CLASS (bamf_view_parent_class)->dispose (object);
}
const char *
_bamf_view_get_path (BamfView *view)
{
g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
if (G_IS_DBUS_PROXY (view->priv->proxy))
return g_dbus_proxy_get_object_path (G_DBUS_PROXY (view->priv->proxy));
return NULL;
}
void
_bamf_view_reset_flags (BamfView *view)
{
g_return_if_fail (BAMF_IS_VIEW (view));
/* Notifying proxy properties makes the view to emit proper signals */
g_object_notify (G_OBJECT (view->priv->proxy), "user-visible");
g_object_notify (G_OBJECT (view->priv->proxy), "active");
g_object_notify (G_OBJECT (view->priv->proxy), "starting");
g_object_notify (G_OBJECT (view->priv->proxy), "running");
g_object_notify (G_OBJECT (view->priv->proxy), "urgent");
g_object_notify (G_OBJECT (view->priv->proxy), "name");
}
void
_bamf_view_set_path (BamfView *view, const char *path)
{
BamfViewPrivate *priv;
GError *error = NULL;
g_return_if_fail (BAMF_IS_VIEW (view));
g_return_if_fail (path);
_bamf_view_set_closed (view, FALSE);
if (g_strcmp0 (_bamf_view_get_path (view), path) == 0)
{
// The proxy path has not been changed, no need to unset and re-set it again
_bamf_view_reset_flags (view);
return;
}
bamf_view_unset_proxy (view);
priv = view->priv;
priv->reload_children = TRUE;
priv->proxy = _bamf_dbus_item_view_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
BAMF_DBUS_SERVICE_NAME,
path, CANCELLABLE (view),
&error);
if (!G_IS_DBUS_PROXY (priv->proxy))
{
g_critical ("Unable to get %s view: %s", BAMF_DBUS_SERVICE_NAME, error ? error ? error->message : "" : "");
g_error_free (error);
return;
}
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
g_object_notify_by_pspec (G_OBJECT (view), properties[PROP_PATH]);
g_signal_connect (priv->proxy, "notify::g-name-owner",
G_CALLBACK (bamf_view_on_name_owner_changed), view);
g_signal_connect (priv->proxy, "notify::active",
G_CALLBACK (bamf_view_on_active_changed), view);
g_signal_connect (priv->proxy, "notify::starting",
G_CALLBACK (bamf_view_on_starting_changed), view);
g_signal_connect (priv->proxy, "notify::running",
G_CALLBACK (bamf_view_on_running_changed), view);
g_signal_connect (priv->proxy, "notify::urgent",
G_CALLBACK (bamf_view_on_urgent_changed), view);
g_signal_connect (priv->proxy, "notify::user-visible",
G_CALLBACK (bamf_view_on_user_visible_changed), view);
g_signal_connect (priv->proxy, "notify::name",
G_CALLBACK (bamf_view_on_name_changed), view);
g_signal_connect (priv->proxy, "notify::icon",
G_CALLBACK (bamf_view_on_icon_changed), view);
g_signal_connect (priv->proxy, "child-added",
G_CALLBACK (bamf_view_on_child_added), view);
g_signal_connect (priv->proxy, "child-removed",
G_CALLBACK (bamf_view_on_child_removed), view);
g_signal_connect (priv->proxy, "closed",
G_CALLBACK (bamf_view_on_closed), view);
_bamf_view_reset_flags (view);
if (BAMF_VIEW_GET_CLASS (view)->set_path)
BAMF_VIEW_GET_CLASS (view)->set_path (view, path);
}
static void
bamf_view_class_init (BamfViewClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
obj_class->dispose = bamf_view_dispose;
obj_class->get_property = bamf_view_get_property;
obj_class->set_property = bamf_view_set_property;
properties[PROP_PATH] = g_param_spec_string ("path", "path", "path", NULL, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_PATH, properties[PROP_PATH]);
properties[PROP_ACTIVE] = g_param_spec_boolean ("active", "active", "active", FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_ACTIVE, properties[PROP_ACTIVE]);
properties[PROP_URGENT] = g_param_spec_boolean ("urgent", "urgent", "urgent", FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_URGENT, properties[PROP_URGENT]);
properties[PROP_STARTING] = g_param_spec_boolean ("starting", "starting", "starting", FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_STARTING, properties[PROP_STARTING]);
properties[PROP_RUNNING] = g_param_spec_boolean ("running", "running", "running", FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_RUNNING, properties[PROP_RUNNING]);
properties[PROP_USER_VISIBLE] = g_param_spec_boolean ("user-visible", "user-visible", "user-visible", FALSE, G_PARAM_READABLE);
g_object_class_install_property (obj_class, PROP_USER_VISIBLE, properties[PROP_USER_VISIBLE]);
g_type_class_add_private (obj_class, sizeof (BamfViewPrivate));
view_signals [ACTIVE_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_ACTIVE_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, active_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
view_signals [CLOSED] =
g_signal_new (BAMF_VIEW_SIGNAL_CLOSED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (BamfViewClass, closed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
view_signals [CHILD_ADDED] =
g_signal_new (BAMF_VIEW_SIGNAL_CHILD_ADDED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, child_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_VIEW);
view_signals [CHILD_REMOVED] =
g_signal_new (BAMF_VIEW_SIGNAL_CHILD_REMOVED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, child_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_VIEW);
view_signals [CHILD_MOVED] =
g_signal_new (BAMF_VIEW_SIGNAL_CHILD_MOVED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, child_moved),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
BAMF_TYPE_VIEW);
view_signals [STARTING_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_STARTING_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, starting_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
view_signals [RUNNING_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_RUNNING_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, running_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
view_signals [URGENT_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_URGENT_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, urgent_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
view_signals [VISIBLE_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_USER_VISIBLE_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (BamfViewClass, user_visible_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
view_signals [NAME_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_NAME_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
0,
G_STRUCT_OFFSET (BamfViewClass, name_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_STRING);
view_signals [ICON_CHANGED] =
g_signal_new (BAMF_VIEW_SIGNAL_ICON_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
0,
G_STRUCT_OFFSET (BamfViewClass, icon_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
G_TYPE_STRING);
}
static void
bamf_view_init (BamfView *self)
{
BamfViewPrivate *priv;
priv = self->priv = BAMF_VIEW_GET_PRIVATE (self);
priv->cancellable = g_cancellable_new ();
priv->is_closed = TRUE;
priv->reload_children = TRUE;
}
./lib/libbamf-private/ 0000755 0000156 0000165 00000000000 12704153435 014713 5 ustar jenkins jenkins ./lib/libbamf-private/org.ayatana.bamf.view.xml 0000644 0000156 0000165 00000013347 12704153435 021526 0 ustar jenkins jenkins
./lib/libbamf-private/Makefile.am 0000644 0000156 0000165 00000001551 12704153435 016751 0 ustar jenkins jenkins include Makefile.am.notparallel
noinst_LTLIBRARIES = libbamf-private.la
bamf_gdbus_files = \
bamf-gdbus-generated.c \
bamf-gdbus-generated.h \
bamf-gdbus-view-generated.c \
bamf-gdbus-view-generated.h \
$(NULL)
bamf_xml_gdbus_files = \
org.ayatana.bamf.xml \
org.ayatana.bamf.view.xml \
$(NULL)
bamf_built_sources = \
$(bamf_gdbus_files) \
$(NULL)
libbamf_private_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(NULL)
libbamf_private_la_LDFLAGS = \
-no-undefined \
$(NULL)
libbamf_private_la_LIBADD = \
$(GLIB_LIBS) \
$(NULL)
libbamf_private_la_SOURCES = \
bamf-private.h \
$(NULL)
nodist_libbamf_private_la_SOURCES = \
$(bamf_built_sources) \
$(NULL)
CLEANFILES = \
$(bamf_built_sources) \
$(NULL)
DISTCLEANFILES = \
$(bamf_built_sources) \
$(NULL)
BUILT_SOURCES = \
$(bamf_gdbus_files) \
$(NULL)
EXTRA_DIST = \
$(bamf_xml_gdbus_files) \
$(NULL)
./lib/libbamf-private/org.ayatana.bamf.xml 0000644 0000156 0000165 00000006251 12704153435 020551 0 ustar jenkins jenkins
./lib/libbamf-private/bamf-private.h 0000644 0000156 0000165 00000002706 12704153435 017446 0 ustar jenkins jenkins /*
* Copyright (C) 2011-2013 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: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*
*/
#ifndef __BAMF_PRIVATE_H__
#define __BAMF_PRIVATE_H__
#include
#include
#define BAMF_DBUS_SERVICE_NAME (g_getenv ("BAMF_TEST_MODE") ? "org.ayatana.bamf.Test" : "org.ayatana.bamf")
#define BAMF_DBUS_BASE_PATH "/org/ayatana/bamf"
#define BAMF_DBUS_CONTROL_PATH BAMF_DBUS_BASE_PATH"/control"
#define BAMF_DBUS_MATCHER_PATH BAMF_DBUS_BASE_PATH"/matcher"
#define BAMF_DBUS_DEFAULT_TIMEOUT 500
#define BAMF_DEFAULT_ICON_SIZE 128
#define BAMF_DEFAULT_MINI_ICON_SIZE 24
/* GLib doesn't provide this by default */
#ifndef G_KEY_FILE_DESKTOP_KEY_FULLNAME
#define G_KEY_FILE_DESKTOP_KEY_FULLNAME "X-GNOME-FullName"
#endif
#define BAMF_APPLICATION_DEFAULT_ICON "application-default-icon"
#endif
./lib/libbamf-private/Makefile.am.notparallel 0000644 0000156 0000165 00000001320 12704153435 021257 0 ustar jenkins jenkins .NOTPARALLEL:
bamf-gdbus-generated.c: org.ayatana.bamf.xml
$(AM_V_GEN) $(GDBUS_CODEGEN) \
--generate-c-code $(shell basename $@ .c) \
--c-namespace BamfDBus \
--interface-prefix org.ayatana.bamf \
$<; \
# Adding '_' prefix to generated private functions \
$(SED) "s/bamf_dbus/_bamf_dbus/g" -i \
$@ $(shell basename $@ .c).h
.NOTPARALLEL:
bamf-gdbus-view-generated.c: org.ayatana.bamf.view.xml
$(AM_V_GEN) $(GDBUS_CODEGEN) \
--c-generate-object-manager \
--generate-c-code $(shell basename $@ .c) \
--c-namespace BamfDBusItem \
--interface-prefix org.ayatana.bamf \
$<; \
# Adding '_' prefix to generated private functions \
$(SED) "s/bamf_dbus_item/_bamf_dbus_item/g" -i \
$@ $(shell basename $@ .c).h
./INSTALL 0000644 0000156 0000165 00000026222 12704153435 012136 0 ustar jenkins jenkins Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007, 2008 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
6. Often, you can also type `make uninstall' to remove the installed
files again.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *Note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
./configure.ac 0000644 0000156 0000165 00000011054 12704153443 013367 0 ustar jenkins jenkins # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT(bamf, 0.5.3, dx-team@canonical.com)
AC_PREREQ(2.69)
AC_SUBST(LIBBAMF_VER, 3)
AC_SUBST(LIBBAMF_SONAME, 2:0:0)
AC_CONFIG_SRCDIR(src/main.c)
AC_CONFIG_HEADERS(config.h)
AM_INIT_AUTOMAKE([foreign tar-pax])
AM_SILENT_RULES([yes])
AC_CONFIG_MACRO_DIR([m4])
GNOME_COMMON_INIT
GNOME_COMPILE_WARNINGS(maximum)
AM_MAINTAINER_MODE
AM_DISABLE_STATIC
AM_PROG_LIBTOOL
AC_ISC_POSIX
AC_SUBST(ACLOCAL_AMFLAFS, "$ACLOCAL_FLAGS -I m4")
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
if test "x$PKG_CONFIG" = "xno"; then AC_MSG_ERROR([You need to install pkg-config]); fi
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_HEADER_STDC
SHAMROCK_EXPAND_LIBDIR
SHAMROCK_EXPAND_BINDIR
SHAMROCK_EXPAND_DATADIR
#
# pkg-config
#
PKG_PROG_PKG_CONFIG
#
# glib
#
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.32.0 gio-2.0 >= 2.30.0 gio-unix-2.0)
#
# gdbus-codegen
#
AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
if test -z "$GDBUS_CODEGEN"; then AC_MSG_ERROR([gdbus-codegen is required but was not found]); fi
#
# libwnck
#
PKG_CHECK_MODULES(WNCK, libwnck-3.0 >= 3.4.7)
#
# libgtop
#
PKG_CHECK_MODULES(GTOP, libgtop-2.0)
#
# libsn
#
PKG_CHECK_MODULES(SN, libstartup-notification-1.0)
#
# x11
#
PKG_CHECK_MODULES(X, x11)
#
# DbusMenu
#
AC_ARG_ENABLE([export-actions-menu],
AS_HELP_STRING([--enable-export-actions-menu=@<:@no/yes@:>@],[export window actions menus (requires dbusmenu) @<:@default=no@:>@]),,
[enable_export_actions_menu=no])
AM_CONDITIONAL([EXPORT_ACTIONS_MENU],[test "x$enable_export_actions_menu" != "xno"])
if test "x$enable_export_actions_menu" = "xyes"; then
PKG_CHECK_MODULES(DBUSMENU, [dbusmenu-glib-0.4, dbusmenu-gtk3-0.4])
fi
###########################
# GObject Introspection
###########################
GOBJECT_INTROSPECTION_CHECK([0.10.2])
###########################
# Vala API Generation
###########################
if test "$enable_introspection" = "yes"; then
AC_PATH_PROG([VALA_API_GEN], [vapigen])
if test -z "$VALA_API_GEN"; then
AC_MSG_ERROR([vapigen is needed to build introspection])
HAVE_INTROSPECTION=0
enable_introspection="no"
fi
fi
###########################
# GTK-DOC
###########################
GTK_DOC_CHECK(1.0)
###########################
# gtester2xunit checks #
###########################
AC_PATH_PROG([PYTHON],[python])
AC_MSG_CHECKING(for gtester2xunit dependencies)
if !($PYTHON -c "import libxslt, libxml2" 2> /dev/null); then
AC_MSG_RESULT([no])
AC_MSG_ERROR([You need to install python-libxslt1 and python-libxml2]);
fi
AC_MSG_RESULT([yes])
###########################
# Headless tests
###########################
AC_ARG_ENABLE([headless-tests],
AS_HELP_STRING([--enable-headless-tests=@<:@no/yes@:>@],[enable headless test suite (requires Xvfb) @<:@default=no@:>@]),,
[enable_headless_tests=no])
AM_CONDITIONAL([ENABLE_HEADLESS_TESTS],[test "x$enable_headless_tests" != "xno"])
if test "x$enable_headless_tests" = "xyes"; then
AC_PATH_PROG([XVFB],[Xvfb])
AC_PATH_PROG([DBUS_LAUNCH],[dbus-launch])
if test -z "$XVFB" -o -z "$DBUS_LAUNCH"; then
AC_MSG_ERROR([Xvfb and dbus-launch are needed for headless-tests])
fi
fi
###########################
# gcov coverage reporting
###########################
AC_TDD_GCOV
AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
AC_SUBST(COVERAGE_CFLAGS)
AC_SUBST(COVERAGE_LDFLAGS)
#
# Gnome/GTK checks
#
AM_PATH_GTK_3_0
dnl CFLAGS
CFLAGS="$CFLAGS -Wall -Werror -Wempty-body -Wformat-security -Winit-self -Warray-bounds -Wimplicit-function-declaration -lm"
AC_SUBST(BAMFDAEMON_CFLAGS)
AC_SUBST(BAMFDAEMON_LIBS)
origgiomodulesdir=`pkg-config --variable=giomoduledir gio-2.0`
# Make giomodulesdir honour 'prefix', so that distcheck works.
giomodulesdir=`echo "$origgiomodulesdir" | sed 's|/usr|${prefix}|'`
AC_SUBST(giomodulesdir)
AC_OUTPUT([
Makefile
lib/libbamf-private/Makefile
lib/libbamf/Makefile
lib/libbamf/libbamf3.pc
src/Makefile
tests/Makefile
tests/bamfdaemon/Makefile
tests/libbamf/Makefile
data/Makefile
doc/Makefile
doc/reference/Makefile
doc/reference/libbamf/Makefile
])
cat <