mirror of
				https://github.com/davatorium/rofi.git
				synced 2025-10-30 23:47:19 -04:00 
			
		
		
		
	Initial pasting support.
This commit is contained in:
		
							parent
							
								
									3188236121
								
							
						
					
					
						commit
						ec538c64ea
					
				
					 3 changed files with 66 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -35,7 +35,7 @@
 | 
			
		|||
 *
 | 
			
		||||
 */
 | 
			
		||||
void history_set ( const char *filename, const char *entry )
 | 
			
		||||
    __attribute__((nonnull));
 | 
			
		||||
__attribute__( ( nonnull ) );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ void history_set ( const char *filename, const char *entry )
 | 
			
		|||
 * Removes the entry from the history.
 | 
			
		||||
 */
 | 
			
		||||
void history_remove ( const char *filename, const char *entry )
 | 
			
		||||
    __attribute__((nonnull));
 | 
			
		||||
__attribute__( ( nonnull ) );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ void history_remove ( const char *filename, const char *entry )
 | 
			
		|||
 * @returns a list of entries length long. (and NULL terminated).
 | 
			
		||||
 */
 | 
			
		||||
char ** history_get_list ( const char *filename, unsigned int * length )
 | 
			
		||||
    __attribute__((nonnull));
 | 
			
		||||
__attribute__( ( nonnull ) );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,12 +19,12 @@ typedef struct
 | 
			
		|||
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
    TB_AUTOHEIGHT = 1 << 0,
 | 
			
		||||
    TB_AUTOWIDTH  = 1 << 1,
 | 
			
		||||
    TB_LEFT       = 1 << 16,
 | 
			
		||||
    TB_RIGHT      = 1 << 17,
 | 
			
		||||
    TB_CENTER     = 1 << 18,
 | 
			
		||||
    TB_EDITABLE   = 1 << 19,
 | 
			
		||||
    TB_AUTOHEIGHT    = 1 << 0,
 | 
			
		||||
        TB_AUTOWIDTH = 1 << 1,
 | 
			
		||||
        TB_LEFT      = 1 << 16,
 | 
			
		||||
        TB_RIGHT     = 1 << 17,
 | 
			
		||||
        TB_CENTER    = 1 << 18,
 | 
			
		||||
        TB_EDITABLE  = 1 << 19,
 | 
			
		||||
} TextboxFlags;
 | 
			
		||||
 | 
			
		||||
typedef enum
 | 
			
		||||
| 
						 | 
				
			
			@ -52,8 +52,10 @@ void textbox_draw ( textbox *tb );
 | 
			
		|||
int textbox_keypress ( textbox *tb, XEvent *ev );
 | 
			
		||||
 | 
			
		||||
void textbox_cursor_end ( textbox *tb );
 | 
			
		||||
void textbox_cursor ( textbox *tb, int pos );
 | 
			
		||||
void textbox_move ( textbox *tb, int x, int y );
 | 
			
		||||
 | 
			
		||||
void textbox_insert ( textbox *tb, int pos, char *str );
 | 
			
		||||
/**
 | 
			
		||||
 * @param tb  Handle to the textbox
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1276,6 +1276,51 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
 | 
			
		|||
                                line_height + ( config.padding ) + ( LINE_MARGIN - 2 ) / 2 );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else if ( ev.type == SelectionNotify )
 | 
			
		||||
            {
 | 
			
		||||
                // TODO move this.
 | 
			
		||||
                Atom utf8 = XInternAtom ( display, "UTF8_STRING", False );
 | 
			
		||||
                if ( ev.xselection.property == utf8 )
 | 
			
		||||
                {
 | 
			
		||||
                    char          *pbuf = NULL;
 | 
			
		||||
                    int           di;
 | 
			
		||||
                    unsigned long dl, rm;
 | 
			
		||||
                    Atom          da;
 | 
			
		||||
 | 
			
		||||
                    /* we have been given the current selection, now insert it into input */
 | 
			
		||||
                    XGetWindowProperty (
 | 
			
		||||
                        display,
 | 
			
		||||
                        main_window,
 | 
			
		||||
                        utf8,
 | 
			
		||||
                        0,
 | 
			
		||||
                        256 / 4,   // max length in words.
 | 
			
		||||
                        False,     // Do not delete clipboard.
 | 
			
		||||
                        utf8, &da, &di, &dl, &rm, (unsigned char * *) &pbuf );
 | 
			
		||||
                    // If There was remaining data left.. lets ignore this.
 | 
			
		||||
                    // Only accept it when we get bytes!
 | 
			
		||||
                    if ( di == 8 )
 | 
			
		||||
                    {
 | 
			
		||||
                        char *index;
 | 
			
		||||
                        if ( ( index = strchr ( pbuf, '\n' ) ) != NULL )
 | 
			
		||||
                        {
 | 
			
		||||
                            // Calc new length;
 | 
			
		||||
                            dl = index - pbuf;
 | 
			
		||||
                        }
 | 
			
		||||
                        // Create a NULL terminated string. I am not sure how the data is returned.
 | 
			
		||||
                        // With or without trailing 0
 | 
			
		||||
                        char str[dl + 1];
 | 
			
		||||
                        memcpy ( str, pbuf, dl );
 | 
			
		||||
                        str[dl] = '\0';
 | 
			
		||||
 | 
			
		||||
                        // Insert string move cursor.
 | 
			
		||||
                        textbox_insert ( text, text->cursor, str );
 | 
			
		||||
                        textbox_cursor ( text, text->cursor + dl );
 | 
			
		||||
                        // Force a redraw
 | 
			
		||||
                        textbox_draw ( text );
 | 
			
		||||
                    }
 | 
			
		||||
                    XFree ( pbuf );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else if ( ev.type == KeyPress )
 | 
			
		||||
            {
 | 
			
		||||
                while ( XCheckTypedEvent ( display, KeyPress, &ev ) )
 | 
			
		||||
| 
						 | 
				
			
			@ -1290,8 +1335,16 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
 | 
			
		|||
 | 
			
		||||
                KeySym key = XkbKeycodeToKeysym ( display, ev.xkey.keycode, 0, 0 );
 | 
			
		||||
 | 
			
		||||
                if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
 | 
			
		||||
                     key == XK_slash )
 | 
			
		||||
                if ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_v )
 | 
			
		||||
                {
 | 
			
		||||
                    // TODO move these.
 | 
			
		||||
                    Atom clip = XInternAtom ( display, "CLIPBOARD", False );
 | 
			
		||||
                    Atom utf8 = XInternAtom ( display, "UTF8_STRING", False );
 | 
			
		||||
                    XConvertSelection ( display, ( ev.xkey.state & ShiftMask ) ? clip : XA_PRIMARY,
 | 
			
		||||
                                        utf8, utf8, main_window, *time );
 | 
			
		||||
                }
 | 
			
		||||
                else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
 | 
			
		||||
                          key == XK_slash )
 | 
			
		||||
                {
 | 
			
		||||
                    retv           = MENU_NEXT;
 | 
			
		||||
                    *selected_line = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue