Example #1
0
static void
test_is_unmanaged ()
{
	ASSERT (is_managed ("eth0"), "test_is_unmanaged",
		"eth0 should be managed");
	ASSERT (!is_managed ("eth4"), "test_is_unmanaged",
		"eth4 should be unmanaged");
}
static GSList *
SCPluginIfnet_get_connections (NMSystemConfigInterface * config)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
	GSList *connections = NULL;
	GHashTableIter iter;
	gpointer key, value;

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) ... get_connections.",
		      GPOINTER_TO_UINT (config));
	if (priv->unmanaged_well_known) {
		PLUGIN_PRINT (IFNET_PLUGIN_NAME,
			      "(%d) ... get_connections (managed=false): return empty list.",
			      GPOINTER_TO_UINT (config));
		return NULL;
	}

	g_hash_table_iter_init (&iter, priv->config_connections);
	while (g_hash_table_iter_next (&iter, &key, &value))
		if (is_managed ((gchar *) key))
			connections = g_slist_prepend (connections, value);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) connections count: %d",
		      GPOINTER_TO_UINT (config), g_slist_length (connections));
	return connections;
}
static void
check_unmanaged (gpointer key, gpointer data, gpointer user_data)
{
	GSList **list = (GSList **) user_data;
	gchar *conn_name = (gchar *) key;
	const char *unmanaged_spec;
	GSList *iter;

	if (is_managed (conn_name))
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Checking unmanaged: %s", conn_name);
	unmanaged_spec = ifnet_get_data (conn_name, "mac");
	if (!unmanaged_spec)
		return;

	/* Just return if the unmanaged spec is already in the list */
	for (iter = *list; iter; iter = g_slist_next (iter)) {
		if (!strcmp ((char *) iter->data, unmanaged_spec))
			return;
	}

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Add unmanaged: %s", unmanaged_spec);
	*list =
	    g_slist_prepend (*list, g_strdup_printf ("mac:%s", unmanaged_spec));
}
Example #4
0
static void
relayout(struct wlc_space *space)
{
   if (!space)
      return;

   struct wl_list *views;
   if (!(views = wlc_space_get_userdata(space)))
      return;

   uint32_t rwidth, rheight;
   struct wlc_output *output = wlc_space_get_output(space);
   wlc_output_get_resolution(output, &rwidth, &rheight);

   struct wlc_view *v;
   uint32_t count = 0;
   wlc_view_for_each_user(v, views)
      if (is_tiled(v)) ++count;

   bool toggle = false;
   uint32_t y = 0, height = rheight / (count > 1 ? count - 1 : 1);
   uint32_t fheight = (rheight > height * (count - 1) ? height + (rheight - height * (count - 1)) : height);
   wlc_view_for_each_user(v, views) {
      if (wlc_view_get_state(v) & WLC_BIT_FULLSCREEN) {
         wlc_view_resize(v, rwidth, rheight);
         wlc_view_position(v, 0, 0);
      }

      if (wlc_view_get_type(v) & WLC_BIT_SPLASH)
         wlc_view_position(v, rwidth * 0.5 - wlc_view_get_width(v) * 0.5, rheight * 0.5 - wlc_view_get_height(v) * 0.5);

      struct wlc_view *parent;
      if (is_managed(v) && !is_or(v) && (parent = wlc_view_get_parent(v)))
         layout_parent(v, parent, wlc_view_get_width(v), wlc_view_get_height(v));

      if (!is_tiled(v))
         continue;

      uint32_t slave = rwidth * loliwm.cut;
      wlc_view_set_state(v, WLC_BIT_MAXIMIZED, true);
      wlc_view_resize(v, (count > 1 ? (toggle ? slave : rwidth - slave) : rwidth), (toggle ? (y == 0 ? fheight : height) : rheight));
      wlc_view_position(v, (toggle ? rwidth - slave : 0), y);

      if (toggle)
         y += (y == 0 ? fheight : height);

      toggle = true;
   }
}
static void
SCPluginIfnet_init (NMSystemConfigInterface * config)
{
	SCPluginIfnet *self = SC_PLUGIN_IFNET (config);
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initializing!");
	if (!priv->config_connections)
		priv->config_connections =
		    g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
					   g_object_unref);
	priv->unmanaged_well_known = !is_managed_plugin ();
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "management mode: %s",
		      priv->unmanaged_well_known ? "unmanaged" : "managed");
	// GFileMonitor setup
	setup_monitors (NULL, config);
	reload_connections (config);
	/* Now if we're running in managed mode, let NM know there are new connections */
	if (!priv->unmanaged_well_known) {
		GHashTableIter iter;
		gpointer key;
		gpointer value;

		g_hash_table_iter_init (&iter, priv->config_connections);
		while (g_hash_table_iter_next (&iter, &key, &value)) {
			if (is_managed ((gchar *) key))
				g_signal_emit_by_name
				    (self,
				     NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
				     NM_EXPORTED_CONNECTION (value));
		}
	}
	/* Read hostname */
	update_system_hostname (self);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initialzation complete!");
}
static void
reload_connections (gpointer config)
{
	SCPluginIfnet *self = SC_PLUGIN_IFNET (config);
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self);
	GList *conn_names = NULL, *n_iter = NULL;

	/* save names for removing unused connections */
	GHashTable *new_conn_names = NULL;
	GHashTableIter iter;
	gpointer key;
	gpointer value;

	if (priv->unmanaged_well_known)
		return;

	if (!reload_parsers ())
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Loading connections");
	conn_names = ifnet_get_connection_names ();
	new_conn_names =
	    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	for (n_iter = conn_names; n_iter; n_iter = g_list_next (n_iter)) {
		NMIfnetConnection *exported;
		NMIfnetConnection *old;
		gchar *conn_name = g_strdup (n_iter->data);

		/* add the new connection */
		exported = nm_ifnet_connection_new (conn_name);
		if (!exported) {
			g_free (conn_name);
			continue;
		}
		g_signal_connect (G_OBJECT (exported), "ifnet_setup_monitors",
				  G_CALLBACK (setup_monitors), config);
		g_signal_connect (G_OBJECT (exported), "ifnet_cancel_monitors",
				  G_CALLBACK (cancel_monitors), config);
		old = g_hash_table_lookup (priv->config_connections, conn_name);
		if (old && exported) {
			gchar *auto_refresh =
			    ifnet_get_global_setting (IFNET_KEY_FILE_GROUP,
						      "auto_refresh");

			if (auto_refresh && is_true (auto_refresh)) {
				if (!nm_connection_compare (NM_CONNECTION (old),
							    NM_CONNECTION
							    (exported),
							    NM_SETTING_COMPARE_FLAG_EXACT))
				{
					PLUGIN_PRINT (IFNET_PLUGIN_NAME,
						      "Auto refreshing %s",
						      conn_name);
					g_signal_emit_by_name (old,
							       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
					g_hash_table_remove
					    (priv->config_connections,
					     conn_name);
					g_hash_table_insert
					    (priv->config_connections,
					     g_strdup (conn_name), exported);
					if (is_managed (conn_name))
						g_signal_emit_by_name (self,
								       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
								       exported);
				}
			} else
				update_old_connection (conn_name, old,
						       exported, priv);
			g_signal_emit_by_name (self,
					       NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
		} else if (exported) {
			g_hash_table_insert (priv->config_connections,
					     g_strdup (conn_name), exported);
			if (is_managed (conn_name))
				g_signal_emit_by_name (self,
						       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
						       exported);
		}
		g_hash_table_insert (new_conn_names, conn_name, conn_name);
	}
	/* remove unused connections */
	g_hash_table_iter_init (&iter, priv->config_connections);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		if (!g_hash_table_lookup (new_conn_names, key)) {
			g_signal_emit_by_name (value,
					       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
			g_hash_table_remove (priv->config_connections, key);
		}
	}
	g_hash_table_remove_all (new_conn_names);
	g_hash_table_destroy (new_conn_names);
	g_list_free (conn_names);
}
Example #7
0
static bool
is_tiled(struct wlc_view *view)
{
   uint32_t state = wlc_view_get_state(view);
   return !(state & WLC_BIT_FULLSCREEN) && !wlc_view_get_parent(view) && is_managed(view) && !is_or(view) && !is_modal(view);
}
static int evcat_new(Evcat **out) {
        _cleanup_(evcat_freep) Evcat *e = NULL;
        int r;

        assert(out);

        e = new0(Evcat, 1);
        if (!e)
                return log_oom();

        r = sd_pid_get_session(getpid(), &e->session);
        if (r < 0)
                return log_error_errno(r, "Cannot retrieve logind session: %m");

        r = sd_session_get_seat(e->session, &e->seat);
        if (r < 0)
                return log_error_errno(r, "Cannot retrieve seat of logind session: %m");

        e->managed = is_managed(e->session);

        r = sd_event_default(&e->event);
        if (r < 0)
                return r;

        r = sd_bus_open_system(&e->bus);
        if (r < 0)
                return r;

        r = sd_bus_attach_event(e->bus, e->event, SD_EVENT_PRIORITY_NORMAL);
        if (r < 0)
                return r;

        r = sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1);
        if (r < 0)
                return r;

        r = sd_event_add_signal(e->event, NULL, SIGTERM, NULL, NULL);
        if (r < 0)
                return r;

        r = sd_event_add_signal(e->event, NULL, SIGINT, NULL, NULL);
        if (r < 0)
                return r;

        r = sysview_context_new(&e->sysview,
                                SYSVIEW_CONTEXT_SCAN_LOGIND |
                                SYSVIEW_CONTEXT_SCAN_EVDEV,
                                e->event,
                                e->bus,
                                NULL);
        if (r < 0)
                return r;

        r = idev_context_new(&e->idev, e->event, e->bus);
        if (r < 0)
                return r;

        *out = e;
        e = NULL;
        return 0;
}