Exemplo n.º 1
0
static int view_driver(struct view *view, int key)
{
	switch (key) 
    {
	case REQ_MOVE_DOWN:
	case REQ_MOVE_UP:
		if (view)
			navigate_view(view, key);
		break;
	case REQ_VIEW_CLOSE:
        quit(0);
        break;
    case REQ_OPEN_VIM:
        report("Shelling out...");
        def_prog_mode();           /* save current tty modes */
        endwin();                  /* end curses mode temporarily */
        system(vim_cmd);           /* run shell */
        report("returned");        /* prepare return message */
        reset_prog_mode();         /* return to the previous tty modes */
        break;
    case REQ_VIEW_MAIN: 
        open_view(view);
        break;
    case REQ_SCREEN_RESIZE:
        resize_display();
        redraw_display(TRUE);
        break;

	default:
		return TRUE;
	}

	return TRUE;
}
Exemplo n.º 2
0
static void open_view(struct view *prev)
{
    struct view *view = &main_view;

    if (view == prev) {
        report("Already in %s view", view->name);
        return;
    }
    
    if (!begin_update(view)) {
        report("Failed to load %s view", view->name);
        return;
    }

    /* Maximize the current view. */
    memset(display, 0, sizeof(display));
    current_view = 0;
    display[current_view] = view; 

    resize_display();

    if (view->pipe) {
        /* Clear the old view and let the incremental updating refill
         * the screen. */
        wclear(view->win);
        report("Loading...");
    }
}
Exemplo n.º 3
0
/*
 * The routine to do the actual talking
 */
void
talk(void)
{
	struct pollfd fds[2];
	char buf[BUFSIZ];
	int nb;

#if defined(NCURSES_VERSION) || defined(beep)
	message("Connection established");
	beep();
	beep();
	beep();
#else
	message("Connection established\007\007\007");
#endif
	current_line = 0;

	/*
	 * Wait on both the other process (sockt_mask) and
	 * standard input ( STDIN_MASK )
	 */
	fds[0].fd = fileno(stdin);
	fds[0].events = POLLIN;
	fds[1].fd = sockt;
	fds[1].events = POLLIN;
	
	for (;;) {
		nb = poll(fds, 2, A_LONG_TIME * 1000);
		if (gotwinch) {
			resize_display();
			gotwinch = 0;
		}
		if (nb <= 0) {
			if (errno == EINTR)
				continue;
			/* panic, we don't know what happened */
			quit("Unexpected error from select", 1);
		}
		if (fds[1].revents & POLLIN) {
			/* There is data on sockt */
			nb = read(sockt, buf, sizeof buf);
			if (nb <= 0)
				quit("Connection closed.  Exiting", 0);
			display(&his_win, buf, nb);
		}
		if (fds[0].revents & POLLIN) {
			/*
			 * We can't make the tty non_blocking, because
			 * curses's output routines would screw up
			 */
			ioctl(0, FIONREAD, &nb);
			nb = read(STDIN_FILENO, buf, nb);
			display(&my_win, buf, nb);
			/* might lose data here because sockt is non-blocking */
			write(sockt, buf, nb);
		}
	}
}
static void
on_allocation_changed (ClutterActor          *actor,
                       ClutterActorBox       *box,
                       ClutterAllocationFlags flags,
                       CalibArea             *area)
{
  if (!gtk_widget_is_visible (area->window))
    return;

  resize_display (area);
}
Exemplo n.º 5
0
Arquivo: prompt.c Projeto: gonzus/tig
static void
prompt_update_display(enum view_flag flags)
{
	struct view *view;
	int i;

	if (flags & VIEW_RESET_DISPLAY) {
		resize_display();
		redraw_display(TRUE);
	}

	foreach_displayed_view(view, i) {
		if (view_has_flags(view, flags) && view_can_refresh(view))
			reload_view(view);
		else
			redraw_view(view);
	}
}
Exemplo n.º 6
0
Arquivo: xxx.c Projeto: yaomoon/GT2440
static void open_view(struct view *prev)
{
    struct view *view = &main_view;

    if (view == prev) {
#ifdef yaomoon
fprintf(moon_log,"830:view==prev\n");
#endif
        report("Already in %s view", view->name);
        return;
    }
    
    if (!begin_update(view)) {
        report("Failed to load %s view", view->name);
        return;
    }

    /* Maximize the current view. */
    memset(display, 0, sizeof(display));
    current_view = 0;
    display[current_view] = view; 

#ifdef yaomoon
fprintf(moon_log,"847:now view is %s\n",display[current_view]->name);
#endif
    resize_display();

    if (view->pipe) {
        /* Clear the old view and let the incremental updating refill
         * the screen. */
        wclear(view->win);
#ifdef yaomoon
fprintf(moon_log,"855: view->pipe\n");
#endif
        report("Loading...");
    }
#ifdef yaomoon
while(1);
#endif
}
Exemplo n.º 7
0
Arquivo: tig.c Projeto: lcd047/tig
static int
view_driver(struct view *view, enum request request)
{
	int i;

	if (request == REQ_NONE)
		return TRUE;

	if (request >= REQ_RUN_REQUESTS) {
		request = open_run_request(view, request);

		// exit quickly rather than going through view_request and back
		if (request == REQ_QUIT)
			return FALSE;
	}

	request = view_request(view, request);
	if (request == REQ_NONE)
		return TRUE;

	switch (request) {
	case REQ_MOVE_UP:
	case REQ_MOVE_DOWN:
	case REQ_MOVE_PAGE_UP:
	case REQ_MOVE_PAGE_DOWN:
	case REQ_MOVE_FIRST_LINE:
	case REQ_MOVE_LAST_LINE:
		move_view(view, request);
		break;

	case REQ_SCROLL_FIRST_COL:
	case REQ_SCROLL_LEFT:
	case REQ_SCROLL_RIGHT:
	case REQ_SCROLL_LINE_DOWN:
	case REQ_SCROLL_LINE_UP:
	case REQ_SCROLL_PAGE_DOWN:
	case REQ_SCROLL_PAGE_UP:
	case REQ_SCROLL_WHEEL_DOWN:
	case REQ_SCROLL_WHEEL_UP:
		scroll_view(view, request);
		break;

	case REQ_VIEW_GREP:
		open_grep_view(view);
		break;

	case REQ_VIEW_MAIN:
	case REQ_VIEW_DIFF:
	case REQ_VIEW_LOG:
	case REQ_VIEW_TREE:
	case REQ_VIEW_HELP:
	case REQ_VIEW_BRANCH:
	case REQ_VIEW_BLAME:
	case REQ_VIEW_BLOB:
	case REQ_VIEW_STATUS:
	case REQ_VIEW_STAGE:
	case REQ_VIEW_PAGER:
	case REQ_VIEW_STASH:
		open_view(view, request, OPEN_DEFAULT);
		break;

	case REQ_NEXT:
	case REQ_PREVIOUS:
		if (view->parent) {
			int line;

			view = view->parent;
			line = view->pos.lineno;
			view_request(view, request);
			move_view(view, request);
			if (view_is_displayed(view))
				update_view_title(view);
			if (line != view->pos.lineno)
				view_request(view, REQ_ENTER);
		} else {
			move_view(view, request);
		}
		break;

	case REQ_VIEW_NEXT:
	{
		int nviews = displayed_views();
		int next_view = (current_view + 1) % nviews;

		if (next_view == current_view) {
			report("Only one view is displayed");
			break;
		}

		current_view = next_view;
		/* Blur out the title of the previous view. */
		update_view_title(view);
		report_clear();
		break;
	}
	case REQ_REFRESH:
		report("Refreshing is not supported by the %s view", view->name);
		break;

	case REQ_PARENT:
		report("Moving to parent is not supported by the the %s view", view->name);
		break;

	case REQ_BACK:
		report("Going back is not supported for by %s view", view->name);
		break;

	case REQ_MAXIMIZE:
		if (displayed_views() == 2)
			maximize_view(view, TRUE);
		break;

	case REQ_OPTIONS:
	case REQ_TOGGLE_LINENO:
	case REQ_TOGGLE_DATE:
	case REQ_TOGGLE_AUTHOR:
	case REQ_TOGGLE_FILENAME:
	case REQ_TOGGLE_GRAPHIC:
	case REQ_TOGGLE_REV_GRAPH:
	case REQ_TOGGLE_REFS:
	case REQ_TOGGLE_CHANGES:
	case REQ_TOGGLE_IGNORE_SPACE:
	case REQ_TOGGLE_ID:
	case REQ_TOGGLE_FILES:
	case REQ_TOGGLE_TITLE_OVERFLOW:
	case REQ_TOGGLE_FILE_SIZE:
	case REQ_TOGGLE_UNTRACKED_DIRS:
	case REQ_TOGGLE_VERTICAL_SPLIT:
		{
			char action[SIZEOF_STR] = "";
			enum view_flag flags = toggle_option(view, request, action);
	
			if (flags == VIEW_FLAG_RESET_DISPLAY) {
				resize_display();
				redraw_display(TRUE);
			} else {
				foreach_displayed_view(view, i) {
					if (view_has_flags(view, flags) && !view->unrefreshable)
						reload_view(view);
					else
						redraw_view(view);
				}
			}

			if (*action)
				report("%s", action);
		}
		break;

	case REQ_TOGGLE_SORT_FIELD:
	case REQ_TOGGLE_SORT_ORDER:
		report("Sorting is not yet supported for the %s view", view->name);
		break;

	case REQ_DIFF_CONTEXT_UP:
	case REQ_DIFF_CONTEXT_DOWN:
		report("Changing the diff context is not yet supported for the %s view", view->name);
		break;

	case REQ_SEARCH:
	case REQ_SEARCH_BACK:
		search_view(view, request);
		break;

	case REQ_FIND_NEXT:
	case REQ_FIND_PREV:
		find_next(view, request);
		break;

	case REQ_STOP_LOADING:
		foreach_view(view, i) {
			if (view->pipe)
				report("Stopped loading the %s view", view->name),
			end_update(view, TRUE);
		}
		break;

	case REQ_SHOW_VERSION:
		report("tig-%s (built %s)", TIG_VERSION, __DATE__);
		return TRUE;

	case REQ_SCREEN_REDRAW:
		redraw_display(TRUE);
		break;

	case REQ_EDIT:
		report("Nothing to edit");
		break;

	case REQ_ENTER:
		report("Nothing to enter");
		break;

	case REQ_VIEW_CLOSE:
		/* XXX: Mark closed views by letting view->prev point to the
		 * view itself. Parents to closed view should never be
		 * followed. */
		if (view->prev && view->prev != view) {
			maximize_view(view->prev, TRUE);
			view->prev = view;
			break;
		}
		/* Fall-through */
	case REQ_QUIT:
		return FALSE;

	default:
		report("Unknown key, press %s for help",
		       get_view_key(view, REQ_VIEW_HELP));
		return TRUE;
	}

	return TRUE;
}
Exemplo n.º 8
0
Arquivo: prompt.c Projeto: gonzus/tig
enum request
run_prompt_command(struct view *view, const char *argv[])
{
	enum request request;
	const char *cmd = argv[0];
	size_t cmdlen = cmd ? strlen(cmd) : 0;

	if (!cmd)
		return REQ_NONE;

	if (string_isnumber(cmd)) {
		int lineno = view->pos.lineno + 1;

		if (parse_int(&lineno, cmd, 0, view->lines + 1) == SUCCESS) {
			if (!lineno)
				lineno = 1;
			select_view_line(view, lineno - 1);
			report_clear();
		} else {
			report("Unable to parse '%s' as a line number", cmd);
		}
	} else if (iscommit(cmd)) {
		int lineno;

		if (!(view->ops->column_bits & view_column_bit(ID))) {
			report("Jumping to commits is not supported by the %s view", view->name);
			return REQ_NONE;
		}

		for (lineno = 0; lineno < view->lines; lineno++) {
			struct view_column_data column_data = {};
			struct line *line = &view->line[lineno];

			if (view->ops->get_column_data(view, line, &column_data) &&
			    column_data.id &&
			    !strncasecmp(column_data.id, cmd, cmdlen)) {
				string_ncopy(view->env->search, cmd, cmdlen);
				select_view_line(view, lineno);
				report_clear();
				return REQ_NONE;
			}
		}

		report("Unable to find commit '%s'", view->env->search);
		return REQ_NONE;

	} else if (cmdlen > 1 && (cmd[0] == '/' || cmd[0] == '?')) {
		char search[SIZEOF_STR];

		if (!argv_to_string(argv, search, sizeof(search), " ")) {
			report("Failed to copy search string");
			return REQ_NONE;
		}

		if (!strcmp(search + 1, view->env->search))
			return cmd[0] == '/' ? REQ_FIND_NEXT : REQ_FIND_PREV;

		string_ncopy(view->env->search, search + 1, strlen(search + 1));
		return cmd[0] == '/' ? REQ_SEARCH : REQ_SEARCH_BACK;

	} else if (cmdlen > 1 && cmd[0] == '!') {
		struct view *next = &pager_view;
		bool copied;

		/* Trim the leading '!'. */
		argv[0] = cmd + 1;
		copied = argv_format(view->env, &next->argv, argv, FALSE, TRUE);
		argv[0] = cmd;

		if (!copied) {
			report("Argument formatting failed");
		} else {
			/* When running random commands, initially show the
			 * command in the title. However, it maybe later be
			 * overwritten if a commit line is selected. */
			argv_to_string(next->argv, next->ref, sizeof(next->ref), " ");

			next->dir = NULL;
			open_pager_view(view, OPEN_PREPARED | OPEN_WITH_STDERR);
		}

	} else if (!strcmp(cmd, "save-display")) {
		const char *path = argv[1] ? argv[1] : "tig-display.txt";

		if (!save_display(path))
			report("Failed to save screen to %s", path);
		else
			report("Saved screen to %s", path);

	} else if (!strcmp(cmd, "exec")) {
		struct run_request req = { view->keymap, {}, argv + 1 };
		enum status_code code = parse_run_request_flags(&req.flags, argv + 1);

		if (code != SUCCESS) {
			report("Failed to execute command: %s", get_status_message(code));
		} else {
			return exec_run_request(view, &req);
		}

	} else if (!strcmp(cmd, "toggle")) {
		enum view_flag flags = VIEW_NO_FLAGS;
		enum status_code code = prompt_toggle(view, argv, &flags);
		const char *action = get_status_message(code);

		if (code != SUCCESS) {
			report("%s", action);
			return REQ_NONE;
		}

		prompt_update_display(flags);

		if (*action)
			report("%s", action);

	} else if (!strcmp(cmd, "script")) {
		if (is_script_executing()) {
			report("Scripts cannot be run from scripts");
		} else if (!open_script(argv[1])) {
			report("Failed to open %s", argv[1]);
		}

	} else {
		struct key key = {};
		enum status_code code;
		enum view_flag flags = VIEW_NO_FLAGS;

		/* Try :<key> */
		key.modifiers.multibytes = 1;
		string_ncopy(key.data.bytes, cmd, cmdlen);
		request = get_keybinding(view->keymap, &key, 1);
		if (request != REQ_NONE)
			return request;

		/* Try :<command> */
		request = get_request(cmd);
		if (request != REQ_UNKNOWN)
			return request;

		code = set_option(argv[0], argv_size(argv + 1), &argv[1]);
		if (code != SUCCESS) {
			report("%s", get_status_message(code));
			return REQ_NONE;
		}

		if (!strcmp(cmd, "set")) {
			struct prompt_toggle *toggle;

			toggle = find_prompt_toggle(option_toggles, ARRAY_SIZE(option_toggles),
						    "", argv[1], strlen(argv[1]));

			if (toggle)
				flags = toggle->flags;
		}

		if (flags) {
			prompt_update_display(flags);

		} else {
			request = view_can_refresh(view) ? REQ_REFRESH : REQ_SCREEN_REDRAW;
			if (!strcmp(cmd, "color"))
				init_colors();
			resize_display();
			redraw_display(TRUE);
		}

	}
	return REQ_NONE;
}
Exemplo n.º 9
0
void renderLoop() {

    int i;
    int x, y;
    int index;
    short pcm_data[2][512];

    while ( 1 ) {
        projectMEvent evt;
        projectMKeycode key;
        projectMModifier mod;

        /** Process SDL events */
        SDL_Event event;
        while ( SDL_PollEvent( &event ) ) {
            /** Translate into projectM codes and process */
            evt = sdl2pmEvent( event );
            key = sdl2pmKeycode( event.key.keysym.sym );
            mod = sdl2pmModifier( event.key.keysym.mod );

	    if ( evt == PROJECTM_KEYDOWN ) {                 
     

                if(key == PROJECTM_K_f)
                {                       
		  if (++fullscreen%2)
		    {
		      resize_display(fvw, fvh, fullscreen%2);
		      globalPM->projectM_resetGL( fvw, fvh ); 
		    }
		  else
		    {
		      resize_display(wvw, wvh, fullscreen%2);
		      globalPM->projectM_resetGL( wvw, wvh ); 
		    }
                }
		else if(key == PROJECTM_K_q || key == PROJECTM_K_ESCAPE) {delete(globalPM); exit (1);}
                else  {globalPM->key_handler(evt,key,mod);}

            }
            else if ( evt == PROJECTM_VIDEORESIZE )
            {
                wvw=event.resize.w;
                wvh=event.resize.h;
                resize_display(wvw, wvh, fullscreen%2);
                globalPM->projectM_resetGL(  wvw, wvh ); 

            } 

          }



        /** Render the new frame */
        globalPM->renderFrame( );

      
        SDL_GL_SwapBuffers();
      }
	
  printf("Worker thread: Exiting\n");
  }
Exemplo n.º 10
0
int
get_input(int prompt_position, struct key_input *input, bool modifiers)
{
	struct view *view;
	int i, key, cursor_y, cursor_x;

	if (prompt_position)
		input_mode = TRUE;

	memset(input, 0, sizeof(*input));

	while (TRUE) {
		bool loading = FALSE;

		foreach_view (view, i) {
			update_view(view);
			if (view_is_displayed(view) && view->has_scrolled &&
			    use_scroll_redrawwin)
				redrawwin(view->win);
			view->has_scrolled = FALSE;
			if (view->pipe)
				loading = TRUE;
		}

		/* Update the cursor position. */
		if (prompt_position) {
			getbegyx(status_win, cursor_y, cursor_x);
			cursor_x = prompt_position;
		} else {
			view = display[current_view];
			getbegyx(view->win, cursor_y, cursor_x);
			cursor_x = view->width - 1;
			cursor_y += view->pos.lineno - view->pos.offset;
		}
		setsyx(cursor_y, cursor_x);

		/* Refresh, accept single keystroke of input */
		doupdate();
		nodelay(status_win, loading);
		key = wgetch(status_win);

		/* wgetch() with nodelay() enabled returns ERR when
		 * there's no input. */
		if (key == ERR) {

		} else if (key == KEY_ESC && modifiers) {
			input->modifiers.escape = 1;

		} else if (key == KEY_RESIZE) {
			int height, width;

			getmaxyx(stdscr, height, width);

			wresize(status_win, 1, width);
			mvwin(status_win, height - 1, 0);
			wnoutrefresh(status_win);
			resize_display();
			redraw_display(TRUE);

		} else {
			int pos, key_length;

			input_mode = FALSE;
			if (key == erasechar())
				key = KEY_BACKSPACE;

			/*
			 * Ctrl-<key> values are represented using a 0x1F
			 * bitmask on the key value. To 'unmap' we assume that:
			 *
			 * - Ctrl-Z is handled by Ncurses.
			 * - Ctrl-m is the same as Return/Enter.
			 * - Ctrl-i is the same as Tab.
			 *
			 * For all other key values in the range the Ctrl flag
			 * is set and the key value is updated to the proper
			 * ASCII value.
			 */
			if (KEY_CTL('a') <= key && key <= KEY_CTL('x') && key != KEY_RETURN && key != KEY_TAB) {
				input->modifiers.control = 1;
				key = key | 0x40;
			}

			if ((key >= KEY_MIN && key < KEY_MAX) || key < 0x1F) { // || key == ' ') {
				input->data.key = key;
				return input->data.key;
			}

			input->modifiers.multibytes = 1;
			input->data.bytes[0] = key;

			key_length = utf8_char_length(input->data.bytes);
			for (pos = 1; pos < key_length && pos < sizeof(input->data.bytes) - 1; pos++) {
				input->data.bytes[pos] = wgetch(status_win);
			}

			return OK;
		}
	}
Exemplo n.º 11
0
Arquivo: prompt.c Projeto: bbolli/tig
enum request
run_prompt_command(struct view *view, const char *argv[])
{
	enum request request;
	const char *cmd = argv[0];
	size_t cmdlen = cmd ? strlen(cmd) : 0;

	if (!cmd)
		return REQ_NONE;

	if (string_isnumber(cmd)) {
		int lineno = view->pos.lineno + 1;

		if (parse_int(&lineno, cmd, 1, view->lines + 1) == SUCCESS) {
			select_view_line(view, lineno - 1);
			report_clear();
		} else {
			report("Unable to parse '%s' as a line number", cmd);
		}
	} else if (iscommit(cmd)) {
		string_ncopy(view->env->search, cmd, cmdlen);
		return REQ_JUMP_COMMIT;

	} else if (cmdlen > 1 && (cmd[0] == '/' || cmd[0] == '?')) {
		char search[SIZEOF_STR];

		if (!argv_to_string(argv, search, sizeof(search), " ")) {
			report("Failed to copy search string");
			return REQ_NONE;
		}

		if (!strcmp(search + 1, view->env->search))
			return cmd[0] == '/' ? REQ_FIND_NEXT : REQ_FIND_PREV;

		string_ncopy(view->env->search, search + 1, strlen(search + 1));
		return cmd[0] == '/' ? REQ_SEARCH : REQ_SEARCH_BACK;

	} else if (cmdlen > 1 && cmd[0] == '!') {
		struct view *next = &pager_view;
		bool copied;

		/* Trim the leading '!'. */
		argv[0] = cmd + 1;
		copied = argv_format(view->env, &next->argv, argv, FALSE, TRUE);
		argv[0] = cmd;

		if (!copied) {
			report("Argument formatting failed");
		} else {
			/* When running random commands, initially show the
			 * command in the title. However, it maybe later be
			 * overwritten if a commit line is selected. */
			argv_to_string(next->argv, next->ref, sizeof(next->ref), " ");

			next->dir = NULL;
			open_pager_view(view, OPEN_PREPARED | OPEN_WITH_STDERR);
		}

	} else if (!strcmp(cmd, "toggle")) {
		char action[SIZEOF_STR] = "";
		enum view_flag flags = prompt_toggle(view, argv, action);
		int i;

		if (flags & VIEW_RESET_DISPLAY) {
			resize_display();
			redraw_display(TRUE);
		}

		foreach_displayed_view(view, i) {
			if (view_has_flags(view, flags) && !view->unrefreshable)
				reload_view(view);
			else
				redraw_view(view);
		}

		if (*action)
			report("%s", action);

	} else {
static void
draw(GtkWidget *widget, cairo_t *cr, gpointer data)
{
    CalibArea *calib_area = (CalibArea*)data;
    int i;
    double x;
    double y;
    PangoLayout *layout;
    PangoRectangle logical_rect;
    GtkStyleContext *context;
    char *markup;

    resize_display(calib_area);

    context = gtk_widget_get_style_context (widget);

    /* Black background and reset the operator */
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

    /* If calibration is successful, just draw the tick */
    if (calib_area->icon_success) {
        draw_success_icon (calib_area, cr);
        return;
    }

    /* Print the help lines */
    layout = pango_layout_new (gtk_widget_get_pango_context (widget));
    pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
    markup = g_strdup_printf ("<span foreground=\"white\"><big><b>%s</b></big>\n<big>%s</big></span>",
			      _(HELP_TEXT_TITLE),
			      _(HELP_TEXT_MAIN));
    pango_layout_set_markup (layout, markup, -1);
    g_free (markup);

    pango_layout_get_pixel_extents (layout, NULL, &logical_rect);

    x = (calib_area->display_width - logical_rect.width) / 2 + logical_rect.x;
    y = (calib_area->display_height - logical_rect.height) / 2  - logical_rect.height - 40 + logical_rect.y;

    gtk_render_layout (context, cr,
		       x + logical_rect.x,
		       y + logical_rect.y,
		       layout);
    g_object_unref (layout);

    /* Draw the points */
    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);

    i = calib_area->calibrator.num_clicks;

    cairo_set_line_width(cr, 1);
    cairo_move_to(cr, calib_area->X[i] - CROSS_LINES, calib_area->Y[i] - 0.5);
    cairo_rel_line_to(cr, CROSS_LINES*2, 0);
    cairo_move_to(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - CROSS_LINES);
    cairo_rel_line_to(cr, 0, CROSS_LINES*2);
    cairo_stroke(cr);

    cairo_set_line_width(cr, 2);
    cairo_arc(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - 0.5, CROSS_CIRCLE, 0.0, 2.0 * M_PI);
    cairo_stroke(cr);

    cairo_set_line_width(cr, 5);
    cairo_arc(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - 0.5, CROSS_CIRCLE2, 0.0, 2.0 * M_PI);
    cairo_stroke(cr);

    /* Draw the clock background */
    cairo_arc(cr, calib_area->display_width/2, calib_area->display_height/2, CLOCK_RADIUS/2, 0.0, 2.0 * M_PI);
    cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
    cairo_fill_preserve(cr);
    cairo_stroke(cr);

    cairo_set_line_width(cr, CLOCK_LINE_WIDTH);
    cairo_arc(cr, calib_area->display_width/2, calib_area->display_height/2, (CLOCK_RADIUS - CLOCK_LINE_WIDTH - CLOCK_LINE_PADDING)/2,
         3/2.0*M_PI, (3/2.0*M_PI) + ((double)calib_area->time_elapsed/(double)MAX_TIME) * 2*M_PI);
    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
    cairo_stroke(cr);

    /* Draw the message (if any) */
    if (calib_area->message != NULL)
    {
        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);

        /* Frame the message */
        layout = pango_layout_new (gtk_widget_get_pango_context (widget));
        pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
        markup = g_strdup_printf ("<span foreground=\"white\"><big>%s</big></span>",
				  _(calib_area->message));
        pango_layout_set_markup (layout, markup, -1);
        g_free (markup);
        pango_layout_get_pixel_extents (layout, NULL, &logical_rect);

        x = (calib_area->display_width - logical_rect.width) / 2 + logical_rect.x;
        y = (calib_area->display_height - logical_rect.height + CLOCK_RADIUS) / 2 + 60 + logical_rect.y;
        cairo_set_line_width(cr, 2);
        cairo_rectangle(cr, x - 10 - 0.5 , y - 10 - 0.5,
                logical_rect.width + 20 + 1, logical_rect.height + 20 + 1);
        cairo_stroke (cr);

        /* Print the message */
	gtk_render_layout (context, cr,
			   x + logical_rect.x,
			   y + logical_rect.y,
			   layout);
	g_object_unref (layout);
    }
}
void renderLoop() {
	while (1) {
		projectMEvent evt;
		projectMKeycode key;
		projectMModifier mod;

		/** Process SDL events */
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			/** Translate into projectM codes and process */
			evt = sdl2pmEvent(event);
            key = sdl2pmKeycode(event.key.keysym.sym, event.key.keysym.mod);
			mod = sdl2pmModifier(event.key.keysym.mod);

			switch (evt) {
			case PROJECTM_KEYDOWN:
				switch (key) {
				case PROJECTM_K_ESCAPE:
					delete(globalPM);
					exit(0);
					break;
				case PROJECTM_K_f: {
					fullscreen = !fullscreen;
					if (fullscreen) {
						resize_display(fvw, fvh, fullscreen);
						globalPM->projectM_resetGL(fvw, fvh);
					} else {
						resize_display(wvw, wvh, fullscreen);
						globalPM->projectM_resetGL(wvw, wvh);
					}
					break;
				}
				case PROJECTM_K_q:
					exit(1);
					break;
				default:
					globalPM->key_handler(evt, key, mod);
				}
				break;

			case PROJECTM_VIDEORESIZE:
				wvw = event.resize.w;
				wvh = event.resize.h;
				resize_display(wvw, wvh, 0);
				globalPM->projectM_resetGL(wvw, wvh);
				break;

			default:
				// not for us, give it to projectM
				globalPM->key_handler(evt, key, mod);
				break;
			}
		}

		globalPM->renderFrame();

		if (doTextureTest)
			textureTest();

		SDL_GL_SwapBuffers();
	}
}
Exemplo n.º 14
0
Arquivo: display.c Projeto: zhez/tig
int
get_input(int prompt_position)
{
	struct view *view;
	int i, key, cursor_y, cursor_x;

	if (prompt_position)
		input_mode = TRUE;

	while (TRUE) {
		bool loading = FALSE;

		foreach_view (view, i) {
			update_view(view);
			if (view_is_displayed(view) && view->has_scrolled &&
			    use_scroll_redrawwin)
				redrawwin(view->win);
			view->has_scrolled = FALSE;
			if (view->pipe)
				loading = TRUE;
		}

		/* Update the cursor position. */
		if (prompt_position) {
			getbegyx(status_win, cursor_y, cursor_x);
			cursor_x = prompt_position;
		} else {
			view = display[current_view];
			getbegyx(view->win, cursor_y, cursor_x);
			cursor_x = view->width - 1;
			cursor_y += view->pos.lineno - view->pos.offset;
		}
		setsyx(cursor_y, cursor_x);

		/* Refresh, accept single keystroke of input */
		doupdate();
		nodelay(status_win, loading);
		key = wgetch(status_win);

		/* wgetch() with nodelay() enabled returns ERR when
		 * there's no input. */
		if (key == ERR) {

		} else if (key == KEY_RESIZE) {
			int height, width;

			getmaxyx(stdscr, height, width);

			wresize(status_win, 1, width);
			mvwin(status_win, height - 1, 0);
			wnoutrefresh(status_win);
			resize_display();
			redraw_display(TRUE);

		} else {
			input_mode = FALSE;
			if (key == erasechar())
				key = KEY_BACKSPACE;
			return key;
		}
	}
Exemplo n.º 15
0
void renderLoop() {
	while (1) {
		projectMEvent evt;
		projectMKeycode key;
		projectMModifier mod;

		/** Process SDL events */
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			/** Translate into projectM codes and process */
			evt = sdl2pmEvent(event);
            key = sdl2pmKeycode(event.key.keysym.sym, event.key.keysym.mod);
			mod = sdl2pmModifier(event.key.keysym.mod);

			switch (evt) {
			case PROJECTM_KEYDOWN:
				switch (key) {
				case PROJECTM_K_ESCAPE:
					cleanup();
					break;
				case PROJECTM_K_f: {
					fullscreen = !fullscreen;
					if (fullscreen) {
						resize_display(fvw, fvh, fullscreen);
						globalPM->projectM_resetGL(fvw, fvh);
					} else {
						resize_display(wvw, wvh, fullscreen);
						globalPM->projectM_resetGL(wvw, wvh);
					}
					break;
				}
				case PROJECTM_K_q:
					cleanup();
					break;
				default:
					globalPM->key_handler(evt, key, mod);
				}
				break;

			case PROJECTM_VIDEORESIZE:
				wvw = event.resize.w;
				wvh = event.resize.h;
				resize_display(wvw, wvh, 0);
				globalPM->projectM_resetGL(wvw, wvh);
				break;

			default:
				// not for us, give it to projectM
				globalPM->key_handler(evt, key, mod);
				break;
			}
		}
 fakePCM[0]=0;
        for (int x = 1; x< 512;x++)
        {
                fakePCM[x] = fakePCM[x-1] + (rand()%200 - 100) *.002;
        }


        globalPM->pcm()->addPCMfloat(fakePCM, 512);





		globalPM->renderFrame();

		if (doTextureTest)
			textureTest();

		SDL_GL_SwapBuffers();
	}
}
Exemplo n.º 16
0
void gui_main_loop(WIDGET *base/*,int resx,int resy*/) {
    SDL_Event event;
    Uint8 gui_done=0;
    Uint32 nb_event;
    WIDGET *mouse_focused=NULL; /* mouse focus */
    static WIDGET *key_focused=NULL; /* key focus */
    if (base==NULL)
	return;

    SDL_BlitSurface(desk_buf,NULL,desk_save,NULL);
    gui_redraw(base,SDL_TRUE);

    SDL_EnableUNICODE(1);
    mouse_focused=base->widget_at_pos(base,mouse_x,mouse_y);
    if (base->key_focus)
    	key_focused=base->key_focus->data;
    else
    	key_focused = NULL;
    if (!key_focused)
	key_focused=update_key_focus(base,NULL);
/*
    key_focused=gui_widget_get_next_keyfocus(base);
    if (key_focused) {
	key_focused->flags|=FLAG_FOCUS;
    }
*/

    while (gui_done!=1) {
	if (SDL_WaitEvent(&event) /*&& gui_done!=1*/) 
	{
	    if (event.type == SDL_QUIT) {
		//printf("QUIIT\n");
		gui_exit_app();
		exit(0);
	    }
	    nb_event=0;
	    while(SDL_PollEvent(&event)) {
		if (event.type!=SDL_MOUSEMOTION)
		    break;
	    }
	    switch (event.type) {
	    case SDL_VIDEORESIZE:
		if (resize_display) resize_display(event.resize.w, event.resize.h);
		break;
	    case SDL_KEYDOWN:
		if (event.key.keysym.sym==SDLK_ESCAPE) {
		    gui_done=1;
		    break;
		}
		if ( event.key.keysym.sym==SDLK_TAB) {
		    key_focused=update_key_focus(base,key_focused);
		    break;
		}
		if (key_focused) {
		    WIDGET *t=key_focused;
		    int e=PASS_EVENT;
		    while(t && ((e=t->key(t,&event.key))==PASS_EVENT))
			t=t->father;
		    //printf("Res: %d\n",e);
		    if (e==QUIT_EVENT) gui_done=1;
		} else { /* if no key focus list was setup, we use mouse focus */
		    WIDGET *t=mouse_focused;
		    int e=PASS_EVENT;
		    while(t && ((e=t->key(t,&event.key))==PASS_EVENT))
			t=t->father;
		    if (e==QUIT_EVENT) gui_done=1;
		}
		break;
	    case SDL_MOUSEMOTION: {
		WIDGET *wid;
		WIDGET *t=mouse_focused;
		int e=PASS_EVENT;
/*
		if (event.motion.x>=desk_buf->w) SDL_WarpMouse(desk_buf->w,event.motion.y);
		if (event.motion.y>=desk_buf->h) SDL_WarpMouse(event.motion.x,desk_buf->h);
*/
		/* recalc relative mouse movement since we don't handle
		   all the event.
		*/

		event.motion.xrel=event.motion.x-mouse_x;
		event.motion.yrel=event.motion.y-mouse_y;

		/*curs_rect.x=*/mouse_x=(event.motion.x);//*desk_buf->w)/(float)resx;
		/*curs_rect.y=*/mouse_y=(event.motion.y);//*desk_buf->h)/(float)resy;
		
		//printf("mouse: %d %d\n",mouse_x,mouse_y);
		
		event.motion.x=mouse_x;
		event.motion.y=mouse_y;
		//event.motion.xrel=(event.motion.xrel*desk_buf->w)/(float)resx;
		//event.motion.yrel=(event.motion.yrel*desk_buf->h)/(float)resy;
		while(t && ((e=t->mouse(t,&event.motion))==PASS_EVENT))
		    t=t->father;
		if (e==QUIT_EVENT) gui_done=1;
		
		/* don't change the focus if a button is pressed */
		if (mouse_focused && WID_HAS_MOUSECLICK(mouse_focused)) break; 
		mouse_focused=update_mouse_focus(base,mouse_focused,mouse_x,mouse_y);
	    }
	    break;
	    case SDL_MOUSEBUTTONDOWN:
	    case SDL_MOUSEBUTTONUP: {
		WIDGET *t=mouse_focused;
		int e=PASS_EVENT;

		/* recalc focus */
		mouse_focused=update_mouse_focus(base,mouse_focused,mouse_x,mouse_y);

		event.button.x=mouse_x;
		event.button.y=mouse_y;

		if (event.type==SDL_MOUSEBUTTONUP && first_clicked==event.button.button) {
		    while(t && ((e=t->double_click(t,&event.button))==PASS_EVENT))
			t=t->father;
		    first_clicked=0;
		} else {
		    while(t && ((e=t->click(t,&event.button))==PASS_EVENT))
			t=t->father;
		    if (event.type==SDL_MOUSEBUTTONUP) first_clicked=event.button.button;
		    SDL_AddTimer(450,double_click_timer,NULL);
		}
		
		if (t) {
		    if (event.button.state == SDL_PRESSED)
			t->flags|=FLAG_MOUSECLICK;
		    else
			t->flags&=(~FLAG_MOUSECLICK);
		    /*
		    Uint8 state=t->m_state;
		    switch (event.button.button) {
		    case SDL_BUTTON_LEFT:
			if (event.button.state == SDL_PRESSED) 
			    state|=0x1;
			else
			    state&=(~0x1);
			break;
		    case SDL_BUTTON_MIDDLE:
			if (event.button.state == SDL_PRESSED) 
			    state|=0x2;
			else
			    state&=(~0x2);
			break;
		    case SDL_BUTTON_RIGHT:
			if (event.button.state == SDL_PRESSED) 
			    state|=0x4;
			else
			    state&=(~0x4);
			break;
		    }
		    //printf("state=%d\n",state);
		    t->m_state=state;
		    */
		}
		if (e==QUIT_EVENT) gui_done=1;
	    }
	    break;
	    }
	
	    /* Redraw.. */
	    gui_redraw(base,SDL_TRUE);
	    
	    
	}
    }
    SDL_EnableUNICODE(0);
}
Exemplo n.º 17
0
static Error
handler_script(int fd, struct dispinfo *d)
{
    XEvent event;
    extern char *names[];

    /* check for broken connection */
    XSync(d->disp, 0);
    if (xerror) goto error;

  again:
    /* while there are events waiting for us? */
    while (XPending(d->disp)) {

	XNextEvent(d->disp, &event);
	DXDebug("X", "event %s", names[event.type]);
	if (xerror) goto error;

	switch (event.type) {
	  case Expose:
	    d->refresh = 1;
	    break;

	  case ButtonPress:
	    d->mouse_x = event.xbutton.x;
	    d->mouse_y = event.xbutton.y;
	    d->refresh = 1;
	    switch (event.xbutton.button) {
	      case 1:
		d->query = 1;
		break;
	      case 2:
		DXPrintAlloc(d->which);
		break;
	      default:
		break;
	    }
	    break;

	  case ConfigureNotify:
	    if ((d->win_width != event.xconfigure.width) ||
	        (d->win_height != event.xconfigure.height)) {
		resize_display(d, event.xconfigure.width, 
			       event.xconfigure.height);
		if (xerror) goto error;
		d->refresh = 1;
	    }
	    break;

	  case DestroyNotify:
	    cleanup_memory_visual(d);
	    if (xerror) goto error;
	    return OK;

	  default:
	    break;
	}
    }

    /* no more events pending.  do we need to refresh the window?
     * query what blocks are underneath the mouse location?
     */
    if (d->refresh) {
	report_memory(d);
	d->refresh = 0;
    }
    if (d->query) {
	query_memory(d);
	d->query = 0;
    }

    /* did more events happen while we were reporting or querying memory? */
    if (XPending(d->disp))
	goto again;

    if (xerror) goto error;
    return OK;

error:
    xerror = 0;
    return ERROR;
}
Exemplo n.º 18
0
int worker_func(void*)
{ 
// char projectM_data[1024]; 
 SDL_TimerID title_timer = NULL;
 std::string config_file;
 config_file = read_config();
 ConfigFile config(config_file);

 int wvw = config.read<int>( "Window Width", 512 );
 int wvh = config.read<int>( "Window Height", 512 );

 int fullscreen = 0;
 if (config.read("Fullscreen", true)) fullscreen = 1;
      else fullscreen = 0;

  init_display(wvw,wvh,&fvw,&fvh,fullscreen); 
  SDL_WM_SetCaption("projectM v1.00", "projectM v1.00");

  /** Initialise projectM */
    
  globalPM = new projectM(config_file);
  SDL_SemPost(sem);
  title_timer = SDL_AddTimer(500, get_xmms_title, NULL);
    /** Initialise the thread */
  // SDL_SemTryWait(sem);
  while ( SDL_SemValue(sem)==1 ) {
        projectMEvent evt;
        projectMKeycode key;
        projectMModifier mod;

        /** Process SDL events */
        SDL_Event event;
        while ( SDL_PollEvent( &event ) ) {
            /** Translate into projectM codes and process */
            evt = sdl2pmEvent( event );	  

            key = sdl2pmKeycode( event.key.keysym.sym );
            mod = sdl2pmModifier( event.key.keysym.mod );

            if ( evt == PROJECTM_KEYDOWN ) {
	   
	      if(key == PROJECTM_K_c)
		{
		  //SDL_SaveBMP(screen, "/home/pete/1.bmp");
		  saveSnapshotToFile();
		}
	      if(key == PROJECTM_K_v)
		{
		  // capture++;
		}
	      if(key == PROJECTM_K_f)
		{
		 

		 int w, h;
                    if (fullscreen == 0) {
                        w = fvw;
                        h = fvh;
			fullscreen = 1;
                    } else {
                        w = wvw;
                        h = wvh;
			fullscreen = 0;
                    }
                  
                    resize_display(w, h, fullscreen);
                    globalPM->projectM_resetGL( w, h ); 
                }
	      else  globalPM->key_handler(evt,key,mod);

              }
	    else if ( evt == PROJECTM_VIDEORESIZE )
	      {

	       

		wvw=event.resize.w;
		wvh=event.resize.h;
	       
		
		resize_display(wvw,wvh,fullscreen);
		globalPM->projectM_resetGL( wvw, wvh ); 
 
              } 
	    else if ( evt == PROJECTM_VIDEOQUIT ) {
	      
	      (void) gtk_idle_add (disable_projectm, NULL);
	    }
	}
	
        /** Add the waveform data */
      

        /** Render the new frame */
	//	 strcpy(title,xmms_remote_get_playlist_title(projectM_vtable.xmms_session, xmms_remote_get_playlist_pos(projectM_vtable.xmms_session))); 

	 //printf("%s\n",title);
	// strcpy(globalPM->title,title);
	
	  globalPM->renderFrame();
	
      

        SDL_GL_SwapBuffers();

	if (capture % 2 == 1) saveSnapshotToFile();
	//	SDL_SemPost(sem);
      }

 if(title_timer) 
  	SDL_RemoveTimer(title_timer);
 delete globalPM;


 return 0;
}
Exemplo n.º 19
0
Arquivo: tig.c Projeto: fourks/tig
static enum request
run_prompt_command(struct view *view, char *cmd)
{
	enum request request;

	if (!cmd)
		return REQ_NONE;

	if (string_isnumber(cmd)) {
		int lineno = view->pos.lineno + 1;

		if (parse_int(&lineno, cmd, 1, view->lines + 1) == SUCCESS) {
			select_view_line(view, lineno - 1);
			report_clear();
		} else {
			report("Unable to parse '%s' as a line number", cmd);
		}
	} else if (iscommit(cmd)) {
		string_ncopy(view->env->search, cmd, strlen(cmd));

		request = view_request(view, REQ_JUMP_COMMIT);
		if (request == REQ_JUMP_COMMIT) {
			report("Jumping to commits is not supported by the '%s' view", view->name);
		}

	} else if (strlen(cmd) == 1) {
		struct key_input input = { { cmd[0] } };

		return get_keybinding(&view->ops->keymap, &input);

	} else if (cmd[0] == '/' || cmd[0] == '?') {
		const char *search = cmd + 1;

		if (!strcmp(search, view->env->search))
			return cmd[0] == '/' ? REQ_FIND_NEXT : REQ_FIND_PREV;

		string_ncopy(view->env->search, search, strlen(search));
		return cmd[0] == '/' ? REQ_SEARCH : REQ_SEARCH_BACK;

	} else if (cmd[0] == '!') {
		struct view *next = VIEW(REQ_VIEW_PAGER);
		const char *argv[SIZEOF_ARG];
		int argc = 0;

		cmd++;
		/* When running random commands, initially show the
		 * command in the title. However, it maybe later be
		 * overwritten if a commit line is selected. */
		string_ncopy(next->ref, cmd, strlen(cmd));

		if (!argv_from_string(argv, &argc, cmd)) {
			report("Too many arguments");
		} else if (!argv_format(view->env, &next->argv, argv, FALSE, TRUE)) {
			report("Argument formatting failed");
		} else {
			next->dir = NULL;
			open_view(view, REQ_VIEW_PAGER, OPEN_PREPARED);
		}

	} else {
		request = get_request(cmd);
		if (request != REQ_UNKNOWN)
			return request;

		char *args = strchr(cmd, ' ');
		if (args) {
			*args++ = 0;
			if (set_option(cmd, args) == SUCCESS) {
				request = !view->unrefreshable ? REQ_REFRESH : REQ_SCREEN_REDRAW;
				if (!strcmp(cmd, "color"))
					init_colors();
				resize_display();
				redraw_display(TRUE);
			}
		}
		return request;
	}
	return REQ_NONE;
}