Exemple #1
0
char *
term_minibuf_read (const char *prompt, const char *value, size_t pos,
                   Completion * cp, History * hp)
{
  Window *wp, *old_wp = cur_wp;
  char *s = NULL;
  astr as;

  if (hp)
    prepare_history (hp);

  as = do_minibuf_read (prompt, value, pos, cp, hp);
  if (as)
    {
      s = xstrdup (astr_cstr (as));
      astr_delete (as);
    }

  if (cp != NULL && (get_completion_flags (cp) & CFLAG_POPPEDUP)
      && (wp = find_window ("*Completions*")) != NULL)
    {
      set_current_window (wp);
      if (get_completion_flags (cp) & CFLAG_CLOSE)
        FUNCALL (delete_window);
      else if (get_completion_old_bp (cp))
        switch_to_buffer (get_completion_old_bp (cp));
      set_current_window (old_wp);
    }

  return s;
}
Exemple #2
0
static void load_list_of_scripts(WnckScreen *screen, WnckWindow *window,
											GSList *file_list)
{
	GSList *temp_file_list = file_list;
	// set the window to work on
	set_current_window(window);

	// for every file in the folder - load the script
	if (file_window_open_list != NULL) {

		while(temp_file_list) {
			gchar *filename = (gchar*)temp_file_list->data;

			// is it a LUA file?
			if (g_str_has_suffix((gchar*)filename,".lua")) {

				// init the script, run it
				if (!load_script(global_lua_state, filename)) {
				}

				run_script(global_lua_state);

			}
			temp_file_list=temp_file_list->next;
		}
	}
	return;

}
Exemple #3
0
/*
 * Scroll completions up.
 */
void
completion_scroll_up (void)
{
  Window *wp, *old_wp = cur_wp;
  Point pt;

  wp = find_window ("*Completions*");
  assert (wp != NULL);
  set_current_window (wp);
  pt = get_buffer_pt (cur_bp);
  if (pt.n >= get_buffer_last_line (cur_bp) - get_window_eheight (cur_wp) || !FUNCALL (scroll_up))
    gotobob ();
  set_current_window (old_wp);

  term_redisplay ();
}
Exemple #4
0
void folder_changed_callback(GFileMonitor *mon,
                             GFile *first_file,
                             GFile *second_file,
                             GFileMonitorEvent event,
                             gpointer user_data)
{
	gchar *our_filename = (gchar*)(user_data);

	// If a file is created or deleted, we need to check the file lists again
	if ((event == G_FILE_MONITOR_EVENT_CREATED) ||
	        (event == G_FILE_MONITOR_EVENT_DELETED)) {

		clear_file_lists();

		set_current_window(NULL);
		load_config(our_filename);

		if (debug)
			printf("Files in folder updated!\n - new lists:\n\n");

		print_script_lists();

		if (debug)
			printf("-----------\n");
	}

	// Also monitor if our devilspie2.lua file is changed - since it handles
	// which files are window close or window open scripts.
	if (event == G_FILE_MONITOR_EVENT_CHANGED) {
		if (first_file) {
			gchar *short_filename = g_file_get_basename(first_file);

			if (g_strcmp0(short_filename, "devilspie2.lua")==0) {

				clear_file_lists();

				set_current_window(NULL);
				load_config(our_filename);

				print_script_lists();

				if (debug)
					printf("----------");
			}
		}
	}
}
Exemple #5
0
/*
 * Scroll completions down.
 */
void
completion_scroll_down (void)
{
  Window *wp, *old_wp = cur_wp;
  Point pt;

  wp = find_window ("*Completions*");
  assert (wp != NULL);
  set_current_window (wp);
  pt = get_buffer_pt (cur_bp);
  if (pt.n == 0 || !FUNCALL (scroll_down))
    {
      gotoeob ();
      resync_redisplay (cur_wp);
    }
  set_current_window (old_wp);

  term_redisplay ();
}
Exemple #6
0
/* 15Feb07  Phil McDonald */
int	volume_dir (struct VolData *vol)
{

    int		dir, xdir, ydir, zdir, vu_face;
    float	xwin, ywin;
    GLdouble	x0, y0, z0, x1, y1, z1, dd;
    GLdouble	model_mat[16], proj_mat[16];
    GLint	vu_port[4];



    set_current_window (vol->data_ctx->dpy_ctx);

    glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble *) proj_mat);
    glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble *) model_mat);
    glGetIntegerv (GL_VIEWPORT, (GLint *) vu_port);

    xwin = ((float) (vu_port[0] + vu_port[2])) / 2.0;
    ywin = ((float) (vu_port[1] + vu_port[3])) / 2.0;

    gluUnProject ((GLdouble) xwin, (GLdouble) ywin, (GLdouble) 0.0,
                  (GLdouble *) model_mat, (GLdouble *) proj_mat,
                  (GLint *) vu_port, &x0, &y0, &z0);

    gluUnProject ((GLdouble) xwin, (GLdouble) ywin, (GLdouble) 1.0,
                  (GLdouble *) model_mat, (GLdouble *) proj_mat,
                  (GLint *) vu_port, &x1, &y1, &z1);

    x1 -= x0;
    y1 -= y0;
    z1 -= z0;
    dd  = sqrt ((x1 * x1) + (y1 * y1) + (z1 * z1));

    vol->vu_vec[0] = x1 / dd;
    vol->vu_vec[1] = y1 / dd;
    vol->vu_vec[2] = z1 / dd;

    /* Volume quad direction is opposite the viewing direction */
    xdir     = (vol->vu_vec[0] <= 0.0) ? VOLUME_X_DIR_FLAG : 0;
    ydir     = (vol->vu_vec[1] <= 0.0) ? VOLUME_Y_DIR_FLAG : 0;
    zdir     = (vol->vu_vec[2] <= 0.0) ? VOLUME_Z_DIR_FLAG : 0;
    vol->dir = xdir | ydir | zdir;

    vu_face = 0;
    if (ABS (vol->vu_vec[1]) > ABS (vol->vu_vec[vu_face])) vu_face = 1;
    if (ABS (vol->vu_vec[2]) > ABS (vol->vu_vec[vu_face])) vu_face = 2;
    vol->vu_face = vu_face;


    return vol->dir;
}
Exemple #7
0
/**
 *  load_config
 * Load configuration from a file - From this we set up the lists of files
 * which decides what script to load on what wnck event.
 */
int load_config(gchar *filename)
{
	lua_State *config_lua_state = NULL;
	int result = 0;
	const gchar *current_file = NULL;
	GSList *temp_window_open_file_list = NULL;
	
	// set the current window to NULL, we don't need to be able to modify
	// the windows when reading the config
	set_current_window(NULL);

	// First get list of Lua files in folder - Then read variables from
	// devilspie2.lua and put the files in the required lists.

	gchar *script_folder = g_path_get_dirname(filename);

	GDir *dir = g_dir_open(script_folder, 0, NULL);
	if (!g_file_test(script_folder, G_FILE_TEST_IS_DIR)) {

		printf(_("script_folder isn't a folder."));
		printf("\n");
		return -1;
	}

	int total_number_of_files = 0;

	config_lua_state = init_script();

	if (g_file_test(filename, G_FILE_TEST_EXISTS)) {

		if (load_script(config_lua_state, filename)!=0) {
			printf(_("Error: %s"), filename);
			printf("\n");
			result = -1;
			goto EXITPOINT;
		}

		run_script(config_lua_state);

		file_window_close_list = get_table_of_strings(config_lua_state,
																	 script_folder,
																	 "scripts_window_close");
	}

	// add the files in the folder to our linked list
	while ((current_file = g_dir_read_name(dir))) {

		gchar *temp_filename = g_build_path(G_DIR_SEPARATOR_S,
		                                 script_folder,
		                                 current_file,
		                                 NULL);

		// we only bother with *.lua in the folder
		if (g_str_has_suffix(current_file, ".lua")) {

			if (!is_in_any_list(temp_filename)) {
				temp_window_open_file_list =
					add_lua_file_to_list(temp_window_open_file_list, temp_filename);
			}
			total_number_of_files++;
		}

		g_free(temp_filename);
	}

	file_window_open_list = temp_window_open_file_list;
EXITPOINT:
	if (config_lua_state)
		done_script(config_lua_state);

	return result;
}
static void pop_window(bool animated) {
  window_stack_pop(animated);
  set_current_window(window_get_user_data(window_stack_get_top_window()));
}
static void push_window(BaseWindow* base_window, bool animated) {
  window_stack_push(base_window_get_window(base_window), animated);
  set_current_window(base_window);
}
Exemple #10
0
static void p_channel(char *from, char **ArgList)
{
    char *channel;
    char *user, *host;
    struct channel *chan = NULL;
    struct whowas_list *whowas = NULL;
    int its_me = 0;

    if (!strcmp(ArgList[0], "0")) {
	fake();
	return;
    }

    channel = ArgList[0];
    message_from(channel, LOG_CRAP);
    malloc_strcpy(&joined_nick, from);

    if (!my_stricmp(from, get_server_nickname(from_server))) {
	int refnum;
	Window *old_window = curr_scr_win;
	int switched = 0;

	if (!in_join_list(channel, from_server))
	    add_to_join_list(channel, from_server, curr_scr_win->refnum);
	else {

	    if (curr_scr_win->refnum != (refnum = get_win_from_join_list(channel, from_server))) {
		switched = 1;
		set_current_window(get_window_by_refnum(refnum));
	    }
	}

	if (*channel != '+')
	    send_to_server(SERVER(from_server), "MODE %s\r\nMODE %s b", channel, channel, channel);

	(void) do_hook(JOIN_ME_LIST, "%s", channel);
	its_me = 1;
	chan = add_channel(channel, from_server);
	if (*channel == '+') {
	    got_info(channel, from_server, GOTBANS);
	    got_info(channel, from_server, GOTMODE);
	}
	if (switched)
	    set_current_window(old_window);
    } else {
	int op = 0, vo = 0;
	char *c;

	/* 
	 * Workaround for gratuitous protocol change in ef2.9
	 */
	if ((c = strchr(channel, '\007'))) {
	    for (*c++ = 0; *c; c++) {
		if (*c == 'o')
		    op = 1;
		else if (*c == 'v')
		    vo = 1;
	    }
	}

	chan = add_to_channel(channel, from, from_server, op, vo, FromUserHost, NULL, NULL);
    }

    flush_mode_all(chan);

    user = m_strdup(FromUserHost);
    host = strchr(user, '@');
    *host++ = '\0';

    if (check_ignore(from, FromUserHost, channel, IGNORE_JOINS | IGNORE_CRAP, NULL) != IGNORED && chan) {
	irc_server *irc_serv = NULL;
	char *tmp2 = NULL;

	if (get_int_var(AUTO_NSLOOKUP_VAR) && isdigit(*(host + strlen(host) - 1)))
	    tmp2 = do_nslookup(host);
	message_from(channel, LOG_CRAP);
	if ((whowas = check_whosplitin_buffer(from, FromUserHost, channel, 0)) && (irc_serv = check_split_server(whowas->server1))) {
	    if (do_hook(LLOOK_JOIN_LIST, "%s %s", irc_serv->name, irc_serv->link))
		put_it("%s",
		       convert_output_format(get_format(FORMAT_NETJOIN_FSET), "%s %s %s %d", update_clock(GET_TIME), irc_serv->name,
					     irc_serv->link, 0));
	    remove_split_server(whowas->server1);
	}
	if (do_hook(JOIN_LIST, "%s %s %s", from, channel, tmp2 ? tmp2 : FromUserHost ? FromUserHost : "UnKnown")) {
	    put_it("%s",
		   convert_output_format(get_format(FORMAT_JOIN_FSET), "%s %s %s %s", update_clock(GET_TIME), from,
					 tmp2 ? tmp2 : FromUserHost ? FromUserHost : "UnKnown", channel));
	}
	message_from(NULL, LOG_CRAP);
    }
    set_input_prompt(curr_scr_win, get_string_var(INPUT_PROMPT_VAR), 0);
    update_all_status(curr_scr_win, NULL, 0);
    notify_mark(from, user, host, 1);
    new_free(&user);
}
Exemple #11
0
int
DialogExecute(GtkWidget *parent, void *dialog)
{
  GtkWidget *dlg, *win_ptr, *btn;
  struct DialogType *data;
  gint res_id, lockstate;

  lockstate = DnDLock;
  DnDLock = TRUE;

  data = (struct DialogType *) dialog;

  if (data->widget && (data->parent != parent)) {
#if 1
    gtk_window_set_transient_for(GTK_WINDOW(data->widget), GTK_WINDOW(parent));
    data->parent = parent;
#else
    gtk_widget_destroy(data->widget);
    reset_event();
    data->widget = NULL;
#endif
  }

  if (data->widget == NULL) {
    dlg = gtk_dialog_new_with_buttons(_(data->resource),
				      GTK_WINDOW(parent),
#if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR
				      GTK_DIALOG_USE_HEADER_BAR |
#endif
				      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				      _("_Cancel"), GTK_RESPONSE_CANCEL,
				      NULL);

    gtk_window_set_resizable(GTK_WINDOW(dlg), TRUE);

    g_signal_connect(dlg, "delete-event", G_CALLBACK(dialog_delete_cb), data);
    g_signal_connect(dlg, "destroy", G_CALLBACK(dialog_destroyed_cb), data);
    g_signal_connect(dlg, "key-press-event", G_CALLBACK(dialog_key_down_cb), NULL);

    data->parent = parent;
    data->widget = dlg;
    data->vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg)));
    data->show_cancel = TRUE;
    data->ok_button = _("_OK");

    gtk_window_set_title(GTK_WINDOW(dlg), _(data->resource));

    data->SetupWindow(dlg, data, TRUE);

    gtk_dialog_add_button(GTK_DIALOG(dlg), data->ok_button, GTK_RESPONSE_OK);

    if (! data->show_cancel) {
      btn = gtk_dialog_get_widget_for_response(GTK_DIALOG(dlg), GTK_RESPONSE_CANCEL);
      gtk_widget_hide(btn);
    }

    gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK);
  } else {
    dlg = data->widget;
    data->SetupWindow(dlg, data, FALSE);
  }

  gtk_widget_hide(dlg);
  gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK);
  data->widget = dlg;
  data->ret = IDLOOP;

  gtk_widget_show(dlg);
  win_ptr = get_current_window();
  set_current_window(dlg);
  if (data->focus)
    gtk_widget_grab_focus(data->focus);

  while (data->ret == IDLOOP) {
    res_id = ndialog_run(dlg);

    if (res_id < 0) {
      switch (res_id) {
      case GTK_RESPONSE_OK:
	data->ret = IDOK;
	break;
      default:
	data->ret = IDCANCEL;
	break;
      }
    } else {
      data->ret = res_id;
    }

    if (data->CloseWindow) {
      data->CloseWindow(dlg, data);
    }
  }

  //  gtk_widget_destroy(dlg);
  //  data->widget = NULL;
  set_current_window(win_ptr);
  gtk_widget_hide(dlg);
  reset_event();

  DnDLock = lockstate;

  return data->ret;
}
Exemple #12
0
/**
 * Program main entry
 */
int main(int argc, char *argv[])
{
	static const GOptionEntry options[]= {
		{	"debug",			'd',	0,	G_OPTION_ARG_NONE,		&debug,
			N_("Print debug info to stdout")
		},
		{	"emulate",		'e',	0,	G_OPTION_ARG_NONE,		&emulate,
			N_("Don't apply any rules, only emulate execution")
		},
		{	"folder",			'f',	0,	G_OPTION_ARG_STRING,		&script_folder,
			N_("Search for scripts in this folder"),N_("FOLDER")
		},
		{	"version",		'v',	0,	G_OPTION_ARG_NONE,		&show_version,
			N_("Show Devilspie2 version and quit")
		},
#ifdef HAVE_GTK3
		// libwnck Version Information is only availible if you have
		// libwnck 3.0 or later
		{	"wnck-version",	'w',	0,	G_OPTION_ARG_NONE,		&show_wnck_version,
			N_("Show libwnck version and quit")
		},
#endif
		{ NULL }
	};

	GError *error = NULL;
	GOptionContext *context;

	// Init gettext stuff
	setlocale(LC_ALL, "");

	bindtextdomain(PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "");
	textdomain(PACKAGE);

	gdk_init(&argc, &argv);

	gchar *devilspie2_description =
	    g_strdup_printf(_("apply rules on windows"));

	gchar *full_desc_string = g_strdup_printf("- %s", devilspie2_description);

	context = g_option_context_new(full_desc_string);
	g_option_context_add_main_entries(context,options, NULL);
	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_print(_("option parsing failed: %s"), error->message);
		printf("\n");
		exit(EXIT_FAILURE);
	}

	g_free(full_desc_string);
	g_free(devilspie2_description);

	// if the folder is NULL, default to ~/.config/devilspie2/
	if (script_folder == NULL) {

		temp_folder = g_build_path(G_DIR_SEPARATOR_S,
		                           g_get_user_config_dir(),
		                           "devilspie2",
		                           NULL);

		// check if the folder does exist
		if (!g_file_test(temp_folder, G_FILE_TEST_IS_DIR)) {

			// - and if it doesn't, create it.
			if (g_mkdir(temp_folder, 0700) != 0) {
				printf("%s", _("Couldn't create the default folder for devilspie2 scripts."));
				printf("\n");
				exit(EXIT_FAILURE);
			}
		}

		script_folder = temp_folder;
	}

	if (show_version) {
		printf("Devilspie2 v%s\n\n", DEVILSPIE2_VERSION);
		exit(EXIT_SUCCESS);
	}
#ifdef HAVE_GTK3
	// libwnck Version Information is only availible if you have
	// libwnck 3.0 or later
	if (show_wnck_version) {
		printf("libwnck v%d.%d.%d\n\n",
		       WNCK_MAJOR_VERSION,
		       WNCK_MINOR_VERSION,
		       WNCK_MICRO_VERSION);
		exit(EXIT_SUCCESS);
	}
#endif

#if (GTK_MAJOR_VERSION >= 3)
	if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
		printf("%s", _("An X11 display is required for devilspie2."));
		printf("\n\n");
		return EXIT_FAILURE;
	}

#endif

	if (init_script_error_messages()!=0) {
		printf("%s", _("Couldn't init script error messages!"));
		printf("\n");
		exit(EXIT_FAILURE);
	}

	// set the current window to NULL, we don't need to be able to modify
	// the windows when reading the config
	set_current_window(NULL);

	config_filename =
	    g_build_filename(script_folder, "devilspie2.lua", NULL);

	if (load_config(config_filename) != 0) {

		devilspie_exit();
		return EXIT_FAILURE;
	}

	if (debug) {

		if (emulate) {
			printf("%s", _("Running devilspie2 in debug and emulate mode."));
		} else {
			printf("%s", _("Running devilspie2 in debug mode."));
		}

		printf("\n\n");

		printf(_("Using scripts from folder: %s"), script_folder);

		printf("\n");

		devilspie2_debug = TRUE;
	}

	// Should we only run an emulation (don't modify any windows)
	if (emulate) devilspie2_emulate = emulate;

	GFile *directory_file;
	directory_file = g_file_new_for_path(script_folder);
//	mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_WATCH_MOUNTS,
	mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_NONE,
	                               NULL, NULL);
	if (!mon) {
		printf("%s", _("Couldn't create directory monitor!"));
		printf("\n");
		return EXIT_FAILURE;
	}

	g_signal_connect(mon, "changed", G_CALLBACK(folder_changed_callback),
	                 (gpointer)(config_filename));

	global_lua_state = init_script();
	print_script_lists();

	if (debug) printf("------------\n");

	// remove stuff cleanly
	atexit(devilspie_exit);

	struct sigaction signal_action;

	sigemptyset(&signal_action.sa_mask);
	signal_action.sa_flags = 0;
	signal_action.sa_handler = signal_handler;

	if (sigaction(SIGINT, &signal_action, NULL) == -1) {
		exit(EXIT_FAILURE);
	}

	init_screens();

	loop=g_main_loop_new(NULL, TRUE);
	g_main_loop_run(loop);

	return EXIT_SUCCESS;
}