void cd_rendering_calculate_max_dock_size_3D_plane (CairoDock *pDock)
{
	pDock->pFirstDrawnElement = cairo_dock_calculate_icons_positions_at_rest_linear (pDock->icons, pDock->fFlatDockWidth, pDock->iScrollOffset);
	
	pDock->iMaxDockHeight = (int) ((1 + g_fAmplitude) * pDock->iMaxIconHeight + g_fReflectSize) + g_iconTextDescription.iSize + g_iDockLineWidth + g_iFrameMargin;
	
	double hi = g_fReflectSize + g_iFrameMargin;
	
	double fInclinationOnHorizon = 0, fExtraWidth = 0;
	pDock->iMaxDockWidth = ceil (cairo_dock_calculate_max_dock_width (pDock, pDock->pFirstDrawnElement, pDock->fFlatDockWidth, 1., fExtraWidth));
	fInclinationOnHorizon = 0.5 * pDock->iMaxDockWidth / iVanishingPointY;
	pDock->iDecorationsHeight = hi + (pDock->iMaxIconHeight + g_iFrameMargin) / sqrt (1 + fInclinationOnHorizon * fInclinationOnHorizon);
	fExtraWidth = cairo_dock_calculate_extra_width_for_trapeze (pDock->iDecorationsHeight, fInclinationOnHorizon, g_iDockRadius, g_iDockLineWidth);
	cd_debug ("iMaxDockWidth <- %d; fInclinationOnHorizon <- %.2f; fExtraWidth <- %.2f", pDock->iMaxDockWidth, fInclinationOnHorizon, fExtraWidth);
	
	pDock->iMaxDockWidth = ceil (cairo_dock_calculate_max_dock_width (pDock, pDock->pFirstDrawnElement, pDock->fFlatDockWidth, 1., fExtraWidth));
	cd_debug ("pDock->iMaxDockWidth <- %d", pDock->iMaxDockWidth);
	
	pDock->iDecorationsWidth = pDock->iMaxDockWidth;
	
	pDock->iMinDockWidth = pDock->fFlatDockWidth + fExtraWidth;
	pDock->iMinDockHeight = g_iDockLineWidth + g_iFrameMargin + g_fReflectSize + pDock->iMaxIconHeight;
	
	if (my_pFlatSeparatorSurface[0] == NULL && (my_iDrawSeparator3D == CD_FLAT_SEPARATOR || my_iDrawSeparator3D == CD_PHYSICAL_SEPARATOR))
		cd_rendering_load_flat_separator (CAIRO_CONTAINER (g_pMainDock));
}
void cd_indicator_destroy (CDAppletIndicator *pIndicator)
{
    if (!pIndicator)
        return;
    if (pIndicator->iSidGetMenuOnce != 0)
        g_source_remove (pIndicator->iSidGetMenuOnce);
    if (pIndicator->iSidCheckIndicator != 0)
        g_source_remove (pIndicator->iSidCheckIndicator);
    pIndicator->bConnected = FALSE;
    pIndicator->on_disconnect = NULL;  // since the indicator has been explicitely destroyed, we don't want to call the callback when we'll disconnect from the service.
    cd_debug ("destroy indicator menu...");
    if (pIndicator->pMenu)
        g_object_unref (pIndicator->pMenu);
    cd_debug ("done.");
    if (pIndicator->pServiceProxy)
    {
        g_object_unref (pIndicator->pServiceProxy);
        pIndicator->pServiceProxy = NULL;
    }
    cd_debug ("destroy service...");
    if (pIndicator->service)
    {
        //g_object_unref (pIndicator->service);  // this causes a crash in libindicator (beacuse they keep the service as parameter of the callback 'service_proxy_name_changed'). so just be sure to disconnect from this object, and forget it.
        g_signal_handlers_disconnect_by_func (G_OBJECT(pIndicator->service), G_CALLBACK(connection_changed), pIndicator);
        g_object_weak_unref (G_OBJECT (pIndicator->service),
                             (GWeakNotify)_on_service_destroyed,
                             pIndicator);
        pIndicator->service = NULL;
    }
    cd_debug ("done.");
    g_free (pIndicator);
}
/* Recupere le temps ecoule chaque seconde (pas de signal pour ca).
 */
static void cd_mpris2_get_data (void)
{
	if (myData.iPlayingStatus == PLAYER_PLAYING)
	{
		cd_mpris2_get_time_elapsed ();
		if (myData.iCurrentTime < 0)  // aucune info de temps sur le bus => lecteur ferme.
		{
			myData.iGetTimeFailed ++;  // certains lecteurs (qmmp par exemple) envoient le signal 'playing' trop tot lorsqu'on les relance, ils ne fournissent pas de duree tout de suite, et donc l'applet stoppe. On fait donc 3 tentatives avant de declarer le lecteur ferme.
			cd_debug ("failed to get time %d time(s)", myData.iGetTimeFailed);
			if (myData.iGetTimeFailed > 2)
			{
				cd_debug (" => player is likely closed");
				myData.iPlayingStatus = PLAYER_NONE;
				myData.iCurrentTime = -2;  // le temps etait a -1, on le change pour provoquer un redraw.
			}
		}
		else
			myData.iGetTimeFailed = 0;
	}
	else if (myData.iPlayingStatus != PLAYER_PAUSED)  // en pause le temps reste constant.
	{
		myData.iCurrentTime = 0;
		myData.iGetTimeFailed = 0;
	}
}
static gboolean on_unmap_desklet (GtkWidget* pWidget,
	G_GNUC_UNUSED GdkEvent *pEvent,
	CairoDesklet *pDesklet)
{
	cd_debug ("unmap desklet (bAllowMinimize:%d)", pDesklet->bAllowMinimize);
	if (pDesklet->iVisibility == CAIRO_DESKLET_ON_WIDGET_LAYER)  // on the widget layer, let pass the unmap event..
		return FALSE;
	if (! pDesklet->bAllowMinimize)
	{
		if (pDesklet->pUnmapTimer)
		{
			double fElapsedTime = g_timer_elapsed (pDesklet->pUnmapTimer, NULL);
			cd_debug ("fElapsedTime : %fms", fElapsedTime);
			g_timer_destroy (pDesklet->pUnmapTimer);
			pDesklet->pUnmapTimer = NULL;
			if (fElapsedTime < .2)
				return TRUE;
		}
		gtk_window_present (GTK_WINDOW (pWidget));
	}
	else
	{
		pDesklet->bAllowMinimize = FALSE;
		if (pDesklet->pUnmapTimer == NULL)
			pDesklet->pUnmapTimer = g_timer_new ();  // starts the timer.
	}
	return TRUE;  // stops other handlers from being invoked for the event.
}
// A scroll on the icon
void cd_xkbd_set_prev_next_group (int iDelta)
{
	XklState *state = xkl_engine_get_current_state (myData.pEngine);

	cd_debug ("keyboard current state : %d;%d +%d", state->group, state->indicators, iDelta);
	
	int i = 0, n = xkl_engine_get_num_groups (myData.pEngine);
	g_return_if_fail (n > 0);
	int iCurrentGroup = MAX (0, MIN (n-1, state->group));  // on blinde car libxklavier peut bugger en 64bits.
	const gchar **pGroupNames = xkl_engine_get_groups_names (myData.pEngine);
	do  // on passe au groupe suivant/precedent en sautant les faux (-).
	{
		i ++;
		iCurrentGroup += iDelta;  // xkl_engine_get_next_group ne marche pas.
		if (iCurrentGroup == n)
			iCurrentGroup = 0;
		else if (iCurrentGroup < 0)
			iCurrentGroup = n - 1;
	} while (i < n && (pGroupNames[iCurrentGroup] == NULL || *pGroupNames[iCurrentGroup] == '-'));
	
	state->group = iCurrentGroup;
	cd_debug ("keyboard new state : %d", state->group);
	xkl_engine_allow_one_switch_to_secondary_group (myData.pEngine);  // sert a quoi ??
	
	Window Xid = xkl_engine_get_current_window (myData.pEngine);
	xkl_engine_save_state (myData.pEngine, Xid, state);
	xkl_engine_lock_group (myData.pEngine, state->group);  // sert a quoi ??
}
void cd_NetworkMonitor_get_wired_connection_infos (void)
{
	cd_debug ("%s ()", __func__);
	GHashTable *hProperties;
	GValue *v;
	
	//\_____________ On recupere les proprietes du device "wired"
	hProperties = cairo_dock_dbus_get_all_properties (myData.dbus_proxy_Device_prop, "org.freedesktop.NetworkManager.Device.Wired");
	g_return_if_fail (hProperties != NULL);
	
	v = (GValue *)g_hash_table_lookup (hProperties, "Speed");
	if (v != NULL && G_VALUE_HOLDS_UINT (v))
	{
		myData.iSpeed = g_value_get_uint (v);
		cd_debug("  Vitesse de connexion : %d",myData.iSpeed);
	}
	
	v = (GValue *)g_hash_table_lookup (hProperties, "HwAddress");
	if (v != NULL && G_VALUE_HOLDS_STRING (v))
	{
		myData.cAccessPointHwAdress = g_strdup(g_value_get_string (v));
		cd_debug("  Adresse physique : %s",myData.cAccessPointHwAdress);
	}
	
	myData.iQuality = WIRED_NO_CONNECTION;
	v = (GValue *)g_hash_table_lookup (hProperties, "Carrier");
	if (v != NULL && G_VALUE_HOLDS_BOOLEAN (v))
	{
		if (g_value_get_boolean (v))
			myData.iQuality = WIRED_CONNECTION;
		cd_debug("  cable branche : %d", g_value_get_boolean (v));
	}
	
	g_hash_table_unref (hProperties);
}
gboolean cd_NetworkMonitor_get_connection (void)
{
	cd_debug ("%s ()", __func__);
	
	myData.cServiceName = g_strdup ("org.freedesktop.NetworkManagerUserSettings");
	
	//\_____________ On recupere la liste des connexions disponibles (ce sont les configs tout-en-un de NM).
	DBusGProxy *dbus_proxy_Settings = cairo_dock_create_new_system_proxy (
		myData.cServiceName,
		"/org/freedesktop/NetworkManagerSettings",
		"org.freedesktop.NetworkManagerSettings");
	GPtrArray *paConnections = cairo_dock_dbus_get_array (dbus_proxy_Settings, "ListConnections");
	cd_debug ("%d connections", paConnections->len);
	
	//\_____________ On en choisit une.
	gchar *cConnection;
	uint i;
	for (i = 0; i < paConnections->len; i++)
	{
		cConnection = (gchar *)g_ptr_array_index(paConnections, i);
		cd_debug (" Connection path : %s", cConnection);
		
		myData.cConnection = g_strdup (cConnection);
	}
	
	g_ptr_array_free (paConnections, TRUE);
	g_object_unref (dbus_proxy_Settings);
	
	return (myData.cConnection != NULL);
}
static void _hide_show_appli_icons_on_other_desktops (GldiWindowActor *pAppli, Icon *icon, CairoDock *pMainDock)
{
	if (! myTaskbarParam.bHideVisibleApplis || pAppli->bIsHidden)
	{
		cd_debug ("%s (%p)", __func__, pAppli);
		CairoDock *pParentDock = NULL;
		if (gldi_window_is_on_current_desktop (pAppli))
		{
			cd_debug (" => est sur le bureau actuel.");
			if (cairo_dock_get_icon_container(icon) == NULL)
			{
				pParentDock = gldi_appli_icon_insert_in_dock (icon, pMainDock, ! CAIRO_DOCK_ANIMATE_ICON);
			}
		}
		else
		{
			cd_debug (" => n'est pas sur le bureau actuel.");
			if (cairo_dock_get_icon_container (icon) != NULL)  // if in a dock, detach it
				pParentDock = gldi_appli_icon_detach (icon);
			else  // else if inhibited, detach from the inhibitor
				gldi_window_detach_from_inhibitors (icon->pAppli);
		}
		if (pParentDock != NULL)
			gtk_widget_queue_draw (pParentDock->container.pWidget);
	}
}
int gldi_dialog_show_and_wait (const gchar *cText, Icon *pIcon, GldiContainer *pContainer, const gchar *cIconPath, GtkWidget *pInteractiveWidget)
{
	int iClickedButton = -3;
	GMainLoop *pBlockingLoop = g_main_loop_new (NULL, FALSE);
	gpointer data[2] = {&iClickedButton, pBlockingLoop};  // it's useless to allocate 'data' because this function will wait for an answer

	CairoDialog *pDialog = gldi_dialog_show (cText,
		pIcon,
		pContainer,
		0.,
		cIconPath,
		pInteractiveWidget,
		(CairoDockActionOnAnswerFunc)_cairo_dock_get_answer_from_dialog,
		(gpointer) data,
		(GFreeFunc)_on_free_blocking_dialog);
	
	if (pDialog != NULL)
	{
		pDialog->fAppearanceCounter = 1.;
		cd_debug ("Start the blocking loop...");
		g_main_loop_run (pBlockingLoop);
		cd_debug ("End of the blocking loop -> %d", iClickedButton);
	}

	g_main_loop_unref (pBlockingLoop);
	return iClickedButton;
}
Exemplo n.º 10
0
static gboolean _timer (gpointer data)
{
	CD_APPLET_ENTER;
	time_t t_cur = (time_t) time (NULL);
	if (t_cur >= myConfig.iShutdownTime)
	{
		cd_debug ("shutdown !\n");
		if (g_iDesktopEnv == CAIRO_DOCK_KDE)
			cairo_dock_launch_command ("dbus-send --session --type=method_call --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:2 int32:2");
		else
			cairo_dock_launch_command ("dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop");
		
		myData.iSidTimer = 0;
		CD_APPLET_LEAVE (FALSE);  // inutile de faire quoique ce soit d'autre, puisque l'ordi s'eteint.
	}
	else
	{
		cd_debug ("shutdown in %d minutes", (int) (myConfig.iShutdownTime - t_cur) / 60);
		CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%dmn", (int) ceil ((double)(myConfig.iShutdownTime - t_cur) / 60.));
		CD_APPLET_REDRAW_MY_ICON;
		if (t_cur >= myConfig.iShutdownTime - 60)
			gldi_dialog_show_temporary_with_icon (D_("Your computer will shut-down in 1 minute."), myIcon, myContainer, 8000, "same icon");
	}
	CD_APPLET_LEAVE (TRUE);
	
}
static inline void _compute_icons_grid (CairoDesklet *pDesklet, CDPanelParameters *pPanel)
{
	pPanel->fMargin = .5 * pPanel->iLineWidth + (1. - sqrt (2) / 2) * pPanel->iRadius;
	
	double w = pDesklet->container.iWidth - 2 * pPanel->fMargin;
	double h = pDesklet->container.iHeight - 2 * pPanel->fMargin;
	pPanel->iMainIconSize = MIN (w, h) / 3;
	cd_debug ("  desklet: %dx%d", (int)w, (int)h);
	
	int iNbIcons = 0;
	Icon *pIcon;
	GList *ic;
	for (ic = pDesklet->icons; ic != NULL; ic = ic->next)
	{
		pIcon = ic->data;
		if (! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
			iNbIcons ++;
	}
	pPanel->iNbIcons = iNbIcons;
	
	int dh = myIconsParam.iLabelSize;  // taille verticale ajoutee a chaque icone.
	int dw = 0;  // taille horizontale ajoutee a chaque icone.
	int dx = GAP_X_MIN;  // ecart entre 2 colonnes.
	int dy = GAP_Y_MIN;  // ecart entre 2 lignes.
	h -= pPanel->iMainIconSize;
	if (pPanel->iNbLinesForced == 0)
	{
		int p, q;  // nombre de lignes et colonnes.
		int iSize;
		pPanel->iIconSize = 0, pPanel->iNbLines = 0, pPanel->iNbColumns = 0;
		//g_print ("%d icones sur %dx%d (%d)\n", pPanel->iNbIcons, (int)w, (int)h, myIconsParam.iLabelSize);
		for (p = 1; p <= pPanel->iNbIcons; p ++)
		{
			q = (int) ceil ((double)pPanel->iNbIcons / p);
			iSize = MIN ((h - p * dy) / p - dh, ((w - (q - 1) * dx) / q - dw) / 2);
			cd_debug ("  %dx%d -> %d", p, q, iSize);
			if (iSize > pPanel->iIconSize)
			{
				pPanel->iIconSize = iSize;
				pPanel->iNbLines = p;
				pPanel->iNbColumns = q;
			}
		}
	}
	else
	{
		int p, q;  // nombre de lignes et colonnes.
		pPanel->iNbLines = p = pPanel->iNbLinesForced;
		pPanel->iNbColumns = q = ceil ((double)iNbIcons / pPanel->iNbLinesForced);
		pPanel->iIconSize = MIN ((h - p * dy) / p - dh, ((w - (q - 1) * dx) / q - dw) / 2);
	}
	pPanel->iIconSize = MIN (pPanel->iIconSize, pPanel->iMainIconSize);
	cd_debug (" panel desklet: %dx%d, %d", pPanel->iNbLines, pPanel->iNbColumns, pPanel->iIconSize);
	
	if ((h - pPanel->iNbLines * (pPanel->iIconSize + dh)) / pPanel->iNbLines > dy)
	{
		pPanel->iMainIconSize += h - pPanel->iNbLines * (pPanel->iIconSize + dh + dy);
	}
}
Exemplo n.º 12
0
static void on_properties_changed (DBusGProxy *player_proxy, const gchar *cInterface, GHashTable *pChangedProps, const gchar **cInvalidProps, gpointer data)
{
	g_return_if_fail (cInterface != NULL);
	cd_debug ("");
	GValue *v;
	if (strcmp (cInterface, "org.mpris.MediaPlayer2.Player") == 0)
	{
		v = g_hash_table_lookup (pChangedProps, "PlaybackStatus");
		if (v != NULL && G_VALUE_HOLDS_STRING (v))  // status has changed
		{
			const gchar *cStatus = g_value_get_string (v);  // "Playing", "Paused" or "Stopped"
			myData.iPlayingStatus = _extract_status (cStatus);
			cd_debug ("PlaybackStatus: Status: %s, %d", cStatus, myData.iPlayingStatus);
			
			if (myData.iPlayingStatus == PLAYER_PLAYING)  // le handler est stoppe lorsque le lecteur ne joue rien.
				cd_musicplayer_relaunch_handler ();
			
			cd_musicplayer_update_icon ();
		}
		
		v = g_hash_table_lookup (pChangedProps, "Metadata");
		if (v != NULL && G_VALUE_HOLDS_BOXED (v))
		{
			GHashTable *pMetadata = g_value_get_boxed (v);
			gboolean bTrackHasChanged = _extract_metadata (pMetadata);
			
			if (bTrackHasChanged)  // new song (song changed or started playing)
			{
				myData.iPlayingStatus = PLAYER_PLAYING;  // pour les lecteurs bugues comme Exaile qui envoit un statut "stop" au changement de musique sans envoyer de status "play" par la suite. On considere donc que si le lecteur joue une nouvelle musique, c'est qu'il est en "play".
				cd_musicplayer_update_icon ();
			}
		}
		
		v = g_hash_table_lookup (pChangedProps, "LoopStatus");
		if (v != NULL && G_VALUE_HOLDS_STRING (v))  // loop status has changed
		{
			const gchar *cStatus = g_value_get_string (v);  // "Playlist", "None"
			s_bIsLoop = (cStatus && strcmp (cStatus, "Playlist") == 0);
			cd_debug ("LoopStatus: %s, %d", cStatus, s_bIsLoop);
			s_bGotLoopStatus = TRUE;
		}
		
		v = g_hash_table_lookup (pChangedProps, "Shuffle");
		if (v != NULL && G_VALUE_HOLDS_BOOLEAN (v))  // Shuffle status has changed
		{
			s_bIsShuffle = g_value_get_boolean (v);
			cd_debug ("Shuffle: %d", s_bIsShuffle);
			s_bGotShuffleStatus = TRUE;
		}
	}
	/*else if (strcmp (cInterface, "org.mpris.MediaPlayer2.TrackList") == 0)
	{
		
	}*/
	else
		cd_debug ("Another interface: %s", cInterface);
}
static gboolean on_button_press_desklet(GtkWidget *widget,
	GdkEventButton *pButton,
	CairoDesklet *pDesklet)
{
	if (pButton->button == 1)  // clic gauche.
	{
		if (pButton->type == GDK_BUTTON_PRESS)
		{
			pDesklet->diff_x = - pButton->x;  // pour le deplacement manuel.
			pDesklet->diff_y = - pButton->y;
			cd_debug ("diff : %d;%d", pDesklet->diff_x, pDesklet->diff_y);
		}
		else if (pButton->type == GDK_BUTTON_RELEASE)
		{
			cd_debug ("GDK_BUTTON_RELEASE");
			if (pDesklet->moving)
			{
				pDesklet->moving = FALSE;
			}
			else
			{
				Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
				gpointer data[2] = {pClickedIcon, pDesklet};
				cairo_dock_notify (CAIRO_DOCK_CLICK_ICON, data);
			}
		}
		else if (pButton->type == GDK_2BUTTON_PRESS)
		{
			Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
			gpointer data[2] = {pClickedIcon, pDesklet};
			cairo_dock_notify (CAIRO_DOCK_DOUBLE_CLICK_ICON, data);
		}
	}
	else if (pButton->button == 3 && pButton->type == GDK_BUTTON_PRESS)  // clique droit.
	{
		Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
		GtkWidget *menu = cairo_dock_build_menu (pClickedIcon, CAIRO_CONTAINER (pDesklet));  // genere un CAIRO_DOCK_BUILD_MENU.
		gtk_widget_show_all (menu);
		gtk_menu_popup (GTK_MENU (menu),
			NULL,
			NULL,
			NULL,
			NULL,
			1,
			gtk_get_current_event_time ());
		pDesklet->bInside = FALSE;
		pDesklet->iGradationCount = 0;  // on force le fond a redevenir transparent.
		gtk_widget_queue_draw (pDesklet->pWidget);
	}
	else if (pButton->button == 2 && pButton->type == GDK_BUTTON_PRESS)  // clique milieu.
	{
		gpointer data[2] = {pDesklet->pIcon, pDesklet};
		cairo_dock_notify (CAIRO_DOCK_MIDDLE_CLICK_ICON, data);
	}
	return FALSE;
}
Exemplo n.º 14
0
void cd_toggle_dialog (void)
{
	if (myData.pDialog != NULL)  // the dialog can be opened in the case it was called from the shortkey.
	{
		gldi_object_unref (GLDI_OBJECT(myData.pDialog));
		myData.pDialog = NULL;
	}
	else
	{
		// establish the connection to Zeitgesit.
		if (myData.pLog == NULL)  // first search.
		{
			cd_debug ("first search");
			myData.pLog = zeitgeist_log_new ();  // may launch the Zeitgeist daemon if it's not yet running.
		}
		#ifdef ZEITGEIST_1_0
		if (! zeitgeist_log_is_connected (myData.pLog))
		{
			cd_debug ("not yet connected");
			if (myData.iSidTryDialog == 0)
			{
				myData.iNbTries = 0;
				myData.iSidTryDialog = g_timeout_add_seconds (1, _show_dialog_delayed, NULL);
			}
			return;
		}
		#else
		gboolean bIsConnected;
		g_object_get (G_OBJECT (myData.pLog), "is-connected", &bIsConnected, NULL);
		if (! bIsConnected)
		{
			// will retry when it will be connected
			g_signal_connect (myData.pLog, "notify::is-connected",
				G_CALLBACK (_show_dialog_delayed), NULL);
			return;
		}
		#endif

		// build the dialog and the tree model.
		GtkWidget *pInteractiveWidget = cd_build_events_widget ();
		myData.pDialog = gldi_dialog_show (D_("Browse and search in recent events"),
			myIcon,
			myContainer,
			0,
			"same icon",
			pInteractiveWidget,
			NULL,
			myApplet,
			(GFreeFunc) _on_dialog_destroyed);
		gtk_widget_grab_focus (myData.pEntry);
		
		// trigger the search that will fill the model.
		cd_trigger_search ();
	}
}
static CDWM *_get_prefered_wmc (CDWMIndex iCurrentWm)
{
	cd_debug ("%s (%s, %d)", __func__, myConfig.cWmCompositor, iCurrentWm);
	CDWM *wm;
	if (myConfig.cWmCompositor != NULL)  // a composite WM is defined.
	{
		wm = _get_wm_by_name (myConfig.cWmCompositor);
		if (wm == NULL)  // not one of the known WM -> define and take the custom one.
		{
			wm = _get_wm_by_index (CD_CUSTOM_WMC);
			g_free ((gchar*)wm->cCommand);
			wm->cCommand = g_strdup (myConfig.cWmCompositor);
			return wm;
		}
		else if (wm->bIsAvailable)
			return wm;
	}
	
	// no WM defined, or the one defined is not available -> check if a suitable one is running.
	if (iCurrentWm < NB_WM)  // one of the know WM is running
	{
		if (myData.bIsComposited)  // and it provides composite => let's take it!
		{
			wm = _get_wm_by_index (iCurrentWm);
			if (wm->bIsAvailable)  // just to be sure.
				return wm;
		}
	}
	
	// no succes so far, take the most suitable one.
	int index[NB_COMPOSITE_WM] = {CD_COMPIZ, CD_KWIN, CD_XFWM, CD_METACITY};  // in this order by default.
	switch (g_iDesktopEnv)
	{
		case CAIRO_DOCK_GNOME:
			index[1] = CD_METACITY;
			index[3] = CD_KWIN;
		break;
		case CAIRO_DOCK_XFCE:
			index[1] = CD_XFWM;
			index[2] = CD_KWIN;
		break;
		case CAIRO_DOCK_KDE:
		default:
		break;
	}
	int i;
	for (i = 0; i < NB_COMPOSITE_WM; i ++)
	{
		wm = _get_wm_by_index (index[i]);
		cd_debug (" %d) %s, %d", index[i], wm->cName, wm->bIsAvailable);
		if (wm->bIsAvailable)
			return wm;
	}
	return NULL;
}
static void _activate_nth_icon (guint iKeyVal, guint iModifierType)  // iKeyVal is already in the correct interval.
{
	cd_debug ("%s (%d)", __func__, iKeyVal);
	// get the index of the icon: we want "1" to be the first icon, because it's more natural and it follows the keyboard layout. So "0" will actually be the 10th icon.
	int iIndex;  // from 0
	if (iKeyVal >= GDK_KEY_0 && iKeyVal <= GDK_KEY_9)
	{
		if (iKeyVal == GDK_KEY_0)
			iIndex = 9;
		else
			iIndex = iKeyVal - GDK_KEY_1;
	}
	else
	{
		if (iKeyVal == GDK_KEY_KP_0)
			iIndex = 9;
		else
			iIndex = iKeyVal - GDK_KEY_KP_1;
	}
	cd_debug ("click on %d", iIndex);
	// retrieve the nth icon in the current dock.
	int n = 0;
	Icon *pNthIcon = NULL, *pIcon;
	GList *ic;
	for (ic = myData.pCurrentDock->icons; ic != NULL; ic = ic->next)
	{
		pIcon = ic->data;
		if (! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
		{
			if (n == iIndex)
			{
				pNthIcon = pIcon;
				break;
			}
			n ++;
		}
	}

	// execute the icon directly.
	if (pNthIcon != NULL)
	{
		cd_debug ("click on %s", pNthIcon->cName);
		cd_do_simulate_click (CAIRO_CONTAINER (myData.pCurrentDock), pNthIcon, iModifierType);

		gldi_icon_start_animation (pNthIcon);
		myData.bIgnoreIconState = FALSE;
		if (pNthIcon == myData.pCurrentIcon)
			myData.pCurrentIcon = NULL;  // sinon on va interrompre l'animation en fermant la session.

		cd_do_close_session ();
	}
}
static void _cd_powermanager_dialog (GString *sInfo) {
    cd_debug ("%s", __func__);
    gchar *cIconPath = NULL;

    if (!myData.on_battery || !myData.battery_present)
        cIconPath = g_strdup_printf("%s/%s", MY_APPLET_SHARE_DATA_DIR, "sector.svg");
    else
        cIconPath = g_strdup_printf("%s/%s", MY_APPLET_SHARE_DATA_DIR, "default-battery.svg");

    cd_debug ("%s (%s)", sInfo->str, cIconPath);
    cairo_dock_show_temporary_dialog_with_icon (sInfo->str, myIcon, myContainer, 6000, cIconPath);
    g_free(cIconPath);
}
static GdkFilterReturn
filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
{
	GdkFilterReturn return_val = GDK_FILTER_CONTINUE;
	XEvent *xevent = (XEvent *) gdk_xevent;
	guint event_mods;
	GSList *iter;

	cd_debug ("Got Event! %d, %d", xevent->type, event->type);

	switch (xevent->type) {
	case KeyPress:
		cd_debug ("Got KeyPress! keycode: %d, modifiers: %d",
				xevent->xkey.keycode,
				xevent->xkey.state);

		/*
		 * Set the last event time for use when showing
		 * windows to avoid anti-focus-stealing code.
		 */
		processing_event = TRUE;
		last_event_time = xevent->xkey.time;

		event_mods = xevent->xkey.state & ~(num_lock_mask  |
						    caps_lock_mask |
						    scroll_lock_mask);

		for (iter = bindings; iter != NULL; iter = iter->next) {
			Binding *binding = (Binding *) iter->data;

			if (binding->keycode == xevent->xkey.keycode &&
			    binding->modifiers == event_mods) {

				cd_debug ("Calling handler for '%s'...",
						binding->keystring);

				(binding->handler) (binding->keystring,
						    binding->user_data);
			}
		}

		processing_event = FALSE;
		break;
	case KeyRelease:
		cd_debug ("Got KeyRelease! ");
		break;
	}

	return return_val;
}
void cd_NetworkMonitor_get_wireless_connection_infos (void)
{
	cd_debug ("%s ()", __func__);
	GHashTable *hProperties;
	GValue *v;
	
	g_free (myData.cAccessPointHwAdress);
	myData.cAccessPointHwAdress = NULL;
	myData.iSpeed = 0;
	
	//\_____________ On recupere les proprietes du device "wireless".
	hProperties = cairo_dock_dbus_get_all_properties (myData.dbus_proxy_Device_prop, "org.freedesktop.NetworkManager.Device.Wireless");
	g_return_if_fail (hProperties != NULL);
	
	v = (GValue *)g_hash_table_lookup (hProperties, "Bitrate");
	if (v && G_VALUE_HOLDS_UINT (v))
	{
		myData.iSpeed = g_value_get_uint (v);
		cd_debug ("  Bitrate : %d\n",myData.iSpeed);
	}
	
	v = (GValue *)g_hash_table_lookup (hProperties, "HwAddress");
	if (v && G_VALUE_HOLDS_STRING (v))
	{
		myData.cAccessPointHwAdress = g_strdup(g_value_get_string (v));
		cd_debug ("  Adresse physique : %s\n",myData.cAccessPointHwAdress);
	}
	
	v = (GValue *)g_hash_table_lookup (hProperties, "ActiveAccessPoint");
	if (v && G_VALUE_HOLDS (v, DBUS_TYPE_G_OBJECT_PATH))
	{
		gchar *cAccessPoint = g_value_get_boxed (v);
		cd_debug ("  Access point : %s", cAccessPoint);
		if (cAccessPoint && strncmp (cAccessPoint, "/org/freedesktop/NetworkManager/AccessPoint/", 44) == 0)
		{
			g_free (myData.cAccessPoint);
			myData.cAccessPoint = g_strdup (cAccessPoint);
		}
	}
	
	g_hash_table_unref (hProperties);
	
	//\_____________ On recupere le point d'acces courant sur le bus.
	myData.iQuality = WIFI_QUALITY_NO_SIGNAL;
	if (myData.cAccessPoint != NULL)
	{
		cd_NetworkMonitor_get_new_access_point ();
	}
}
void cd_do_search_matching_icons (void)
{
	if (myData.sCurrentText->len == 0)
		return;
	cd_debug ("%s (%s)", __func__, myData.sCurrentText->str);
	gchar *str = strchr (myData.sCurrentText->str, ' ');  // on ne compte pas les arguments d'une eventuelle commande deja tapee.
	guint length = myData.sCurrentText->len;
	if (str != NULL)
	{
		g_string_set_size (myData.sCurrentText, str - myData.sCurrentText->str + 1);
		cd_debug (" on ne cherchera que '%s' (len=%d)", myData.sCurrentText->str, myData.sCurrentText->len);
	}
		
	if (myData.pMatchingIcons == NULL)
	{
		cd_debug ("on cherche tout\n");
		// on parcours tous les docks.
		gldi_icons_foreach_in_docks ((GldiIconFunc) _cd_do_search_in_one_dock, NULL);
		myData.pMatchingIcons = g_list_reverse (myData.pMatchingIcons);
		
		// on rajoute les icones ne venant pas du dock.
		cd_do_find_matching_applications ();
	}
	else  // optimisation : on peut se contenter de chercher parmi les icones deja trouvees.
	{
		cd_debug ("on se contente d'enlever celles en trop\n");
		GList *ic, *next_ic;
		Icon *pIcon;
		ic = myData.pMatchingIcons;
		while (ic != NULL)
		{
			pIcon = ic->data;
			next_ic = ic->next;
			if (! _cd_do_icon_match (pIcon, myData.sCurrentText->str, myData.sCurrentText->len))
				myData.pMatchingIcons = g_list_delete_link (myData.pMatchingIcons, ic);
			ic = next_ic;
		}
	}
	myData.pCurrentMatchingElement = myData.pMatchingIcons;
	myData.iMatchingGlideCount = 0;
	myData.iPreviousMatchingOffset = 0;
	myData.iCurrentMatchingOffset = 0;
	if (myData.pCurrentApplicationToLoad != NULL)  // on va continuer le chargement sur la sous-liste.
		myData.pCurrentApplicationToLoad = myData.pMatchingIcons;  // comme l'ordre de la liste n'a pas ete altere, on n'est sur de ne pas sauter d'icone.
	cairo_dock_redraw_container (CAIRO_CONTAINER (g_pMainDock));
	//g_print ("%d / %d\n", length , myData.sCurrentText->len);
	if (length != myData.sCurrentText->len)
		g_string_set_size (myData.sCurrentText, length);
}
CairoDialog *gldi_dialog_new (CairoDialogAttr *pAttribute)
{
	if (!pAttribute->bForceAbove)
	{
		GldiWindowActor *pActiveAppli = gldi_windows_get_active ();
		if (pActiveAppli && pActiveAppli->bIsFullScreen && gldi_window_is_on_current_desktop (pActiveAppli))
		{
			cd_debug ("skip dialog since current fullscreen window would mask it");
			return NULL;
		}
	}
	pAttribute->cattr.bNoOpengl = TRUE;
	cd_debug ("%s (%s, %s, %x, %x, (%p;%p))", __func__, pAttribute->cText, pAttribute->cImageFilePath, pAttribute->pInteractiveWidget, pAttribute->pActionFunc, pAttribute->pIcon, pAttribute->pContainer);
	return (CairoDialog*)gldi_object_new (&myDialogObjectMgr, pAttribute);
}
Exemplo n.º 22
0
static void cd_exaile_getCoverPath (void)
{
	gchar *cCoverPath = cairo_dock_dbus_get_string (myData.dbus_proxy_player, "get_cover_path");
	if (g_str_has_suffix (cCoverPath, "nocover.png"))
	{
		g_free (cCoverPath);
		cCoverPath = NULL;
	}
	if (cCoverPath != NULL)
		cd_debug ("MP : Couverture de exaile : %s", cCoverPath);  /// gerer le cas "nocover.jpg" ...
	else
		cd_debug ("MP : Pas de couverture chez exaile\n");
	cd_musicplayer_set_cover_path (cCoverPath);
	g_free (cCoverPath);
}
CDMediaplayerParameters *rendering_configure_mediaplayer (CairoDesklet *pDesklet, cairo_t *pSourceContext, gpointer *pConfig)
{
	cd_debug ("");
	CDMediaplayerParameters *pMediaplayer = g_new0 (CDMediaplayerParameters, 1);
	if (pConfig != NULL)  // dessin de l'artiste et du titre sur le coté du desklet.
	{
		pMediaplayer->cArtist = pConfig[0];
		pMediaplayer->cTitle = pConfig[1];
		if (pMediaplayer->cArtist != NULL)
			pMediaplayer->pArtistSurface = cairo_dock_create_surface_from_text (pMediaplayer->cArtist,
			pSourceContext,
			&g_iconTextDescription,
			cairo_dock_get_max_scale (pDesklet),
			&pMediaplayer->fArtistWidth, &pMediaplayer->fArtistHeight, &pMediaplayer->fArtistXOffset, &pMediaplayer->fArtistYOffset);
		if (pMediaplayer->cTitle != NULL)
			pMediaplayer->pTitleSurface = cairo_dock_create_surface_from_text (pMediaplayer->cTitle,
			pSourceContext,
			&g_iconTextDescription,
			cairo_dock_get_max_scale (pDesklet),
			&pMediaplayer->fTitleWidth, &pMediaplayer->fTitleHeight, &pMediaplayer->fTitleXOffset, &pMediaplayer->fTitleYOffset);
		
		pMediaplayer->bControlButton = GPOINTER_TO_INT (pConfig[2]);
	}
	return pMediaplayer;
}
Exemplo n.º 24
0
static void _insert_error_message (GldiModuleInstance *myApplet, const gchar *cErrorMessage)
{
    cd_debug ("%s (%s, %d)", __func__, cErrorMessage, myData.bError);
    CDRssItem *pItem;
    if (myData.pItemList != NULL)  // on garde la liste courante, mais on insere un message.
    {
        if (! myData.bError)  // pas encore de message d'erreur, on en insere un.
        {
            pItem = g_new0 (CDRssItem, 1);
            pItem->cTitle = g_strdup (D_("Warning: couldn't retrieve data last time we tried."));
            myData.pItemList = g_list_insert (myData.pItemList, pItem, 1);
        }
    }
    else  // aucune liste : c'est la 1ere recuperation => on met le titre si possible, suivi du message d'erreur.
    {
        pItem = g_new0 (CDRssItem, 1);
        myData.pItemList = g_list_prepend (myData.pItemList, pItem);
        if (myConfig.cUserTitle != NULL && myConfig.cUrl != NULL)  // si le titre est connu on l'utilise (si aucun URL n'est defini ce n'est pas pertinent par contre).
        {
            pItem->cTitle = g_strdup (myConfig.cUserTitle);
            pItem = g_new0 (CDRssItem, 1);
            myData.pItemList = g_list_append (myData.pItemList, pItem);
        }
        pItem->cTitle = g_strdup (cErrorMessage);
    }

    myData.bError = TRUE;
}
static void upload (const gchar *cText, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError)
{
	if (cText == NULL || *cText == '\0')
	{
		g_set_error (pError, 1, 1, D_("Your text is empty and couldn't be uploaded to this server"));
		return;
	}

	GError *erreur = NULL;
	// http://pastebin.com/api
	gchar *cResult = cairo_dock_get_url_data_with_post (URL, FALSE, &erreur,
		"api_option", OPTION,
		"api_user_key", "", // guest
		"api_paste_private", bAnonymous ? "1" : "0", // unlisted or public
		"api_paste_name", bAnonymous ? "" : g_getenv ("USER"),
		"api_paste_expire_date", EXPIRE,
		"api_paste_format", FORMAT,
		"api_dev_key", DEV_KEY,
		"api_paste_code", cText,
		NULL);
	if (erreur)
	{
		cd_warning (erreur->message);
		g_error_free (erreur);
		DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("Pastebin.com");
	}
	else
	{
		cd_debug (" --> got '%s'", cResult);
		if (cResult == NULL || ! g_str_has_prefix (cResult, "http"))
			DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("Pastebin.com");
		else
			cResultUrls[0] = cResult;
	}
}
/* Fonction executee à chaque changement de musique.
 */
static void onChangeSong(DBusGProxy *player_proxy, GHashTable *metadata, gpointer data)
{
	CD_APPLET_ENTER;
	cd_debug ("MP : %s ()", __func__);
	
	if (metadata != NULL)
	{
		_extract_metadata (metadata);
	}
	else
	{
		g_free (myData.cPlayingUri);
		myData.cPlayingUri = NULL;
		g_free (myData.cArtist);
		myData.cArtist = NULL;
		g_free (myData.cAlbum);
		myData.cAlbum = NULL;
		g_free (myData.cTitle);
		myData.cTitle = NULL;
		g_free (myData.cCoverPath);
		myData.cCoverPath = NULL;
		myData.iSongLength = 0;
		myData.iTrackNumber = 0;
		myData.cover_exist = FALSE;
	}
	cd_musicplayer_update_icon ();
	CD_APPLET_LEAVE ();
}
static gboolean _cairo_dock_write_desklet_position (CairoDesklet *pDesklet)
{
	if (pDesklet->pIcon != NULL && pDesklet->pIcon->pModuleInstance != NULL)
	{
		int iRelativePositionX = (pDesklet->container.iWindowPositionX + pDesklet->container.iWidth/2 <= gldi_desktop_get_width()/2 ? pDesklet->container.iWindowPositionX : pDesklet->container.iWindowPositionX - gldi_desktop_get_width());
		int iRelativePositionY = (pDesklet->container.iWindowPositionY + pDesklet->container.iHeight/2 <= gldi_desktop_get_height()/2 ? pDesklet->container.iWindowPositionY : pDesklet->container.iWindowPositionY - gldi_desktop_get_height());
		
		int iNumDesktop = -1;
		if (! gldi_desklet_is_sticky (pDesklet))
		{
			iNumDesktop = gldi_container_get_current_desktop_index (CAIRO_CONTAINER (pDesklet));
			//g_print ("desormais on place le desklet sur le bureau (%d,%d,%d)\n", iDesktop, iViewportX, iViewportY);
		}
		cd_debug ("%d; %d; %d", iNumDesktop, iRelativePositionX, iRelativePositionY);
		cairo_dock_update_conf_file (pDesklet->pIcon->pModuleInstance->cConfFilePath,
			G_TYPE_INT, "Desklet", "x position", iRelativePositionX,
			G_TYPE_INT, "Desklet", "y position", iRelativePositionY,
			G_TYPE_INT, "Desklet", "num desktop", iNumDesktop,
			G_TYPE_INVALID);
		gldi_object_notify (pDesklet, NOTIFICATION_CONFIGURE_DESKLET, pDesklet);
	}
	
	if (pDesklet->bSpaceReserved)  // l'espace est reserve, on reserve a la nouvelle position.
	{
		_reserve_space_for_desklet (pDesklet, TRUE);
	}
	if (pDesklet->pIcon && gldi_icon_has_dialog (pDesklet->pIcon))
	{
		gldi_dialogs_replace_all ();
	}
	pDesklet->iSidWritePosition = 0;
	return FALSE;
}
void gldi_desklet_set_sticky (CairoDesklet *pDesklet, gboolean bSticky)
{
	//g_print ("%s (%d)\n", __func__, bSticky);
	int iNumDesktop;
	if (bSticky)
	{
		gtk_window_stick (GTK_WINDOW (pDesklet->container.pWidget));
		iNumDesktop = -1;
	}
	else
	{
		gtk_window_unstick (GTK_WINDOW (pDesklet->container.pWidget));
		int iCurrentDesktop, iCurrentViewportX, iCurrentViewportY;
		gldi_desktop_get_current (&iCurrentDesktop, &iCurrentViewportX, &iCurrentViewportY);
		iNumDesktop = iCurrentDesktop * g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY + iCurrentViewportX * g_desktopGeometry.iNbViewportY + iCurrentViewportY;
		cd_debug (">>> on colle ce desklet sur le bureau %d", iNumDesktop);
	}
	
	//\_________________ On enregistre le nouvel etat.
	Icon *icon = pDesklet->pIcon;
	if (CAIRO_DOCK_IS_APPLET (icon))
		cairo_dock_update_conf_file (icon->pModuleInstance->cConfFilePath,
			G_TYPE_BOOLEAN, "Desklet", "sticky", bSticky,
			G_TYPE_INT, "Desklet", "num desktop", iNumDesktop,
			G_TYPE_INVALID);
}
/* Controle du lecteur
 */
static void cd_quodlibet_control (MyPlayerControl pControl, const char* song)
{
	const gchar *cCommand = NULL;
		
	switch (pControl) {
		case PLAYER_PREVIOUS :
			cCommand = "Previous";
		break;
		
		case PLAYER_PLAY_PAUSE :
			cCommand = "PlayPause";
		break;

		case PLAYER_NEXT :
			cCommand = "Next";
		break;

		default :
			return;
		break;
	}
	
	if (cCommand != NULL)
	{
		cd_debug ("MP : Handler QuodLibet : will use '%s'", cCommand);
		cairo_dock_dbus_call (myData.dbus_proxy_player, cCommand);
	}
}
Exemplo n.º 30
0
static void _on_got_playing_status (DBusGProxy *proxy, DBusGProxyCall *call_id, GldiModuleInstance *myApplet)
{
	cd_debug ("=== %s ()", __func__);
	CD_APPLET_ENTER;
	s_pGetStatusCall = NULL;
	
	gchar *cStatus = NULL;
	GValue v = G_VALUE_INIT;
	GError *erreur = NULL;
	dbus_g_proxy_end_call (proxy,
		call_id,
		&erreur,
		G_TYPE_VALUE, &v,
		G_TYPE_INVALID);
	if (erreur != NULL)
	{
		cd_warning ("couldn't get MPRIS status (%s)\n", erreur->message);
		g_error_free (erreur);
	}
	else
	{
		if (G_VALUE_HOLDS_STRING (&v))
		{
			cStatus = (gchar*)g_value_get_string (&v);
			myData.iPlayingStatus = _extract_status (cStatus);
			g_free (cStatus);  // since we don't destroy the value, we destroy its content.
		}
	}
	
	cd_mpris2_getSongInfos_async ();
	
	CD_APPLET_LEAVE ();
}