2017-04-15 10:32:05 +00:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-30 18:45:08 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <history.h>
|
|
|
|
#include <string.h>
|
2016-02-21 15:40:29 +00:00
|
|
|
#include <xcb/xcb.h>
|
2016-10-08 16:57:59 +00:00
|
|
|
#include <widgets/textbox.h>
|
2014-08-30 18:45:08 +00:00
|
|
|
#include <rofi.h>
|
2016-01-09 15:22:09 +00:00
|
|
|
#include <cairo-xlib.h>
|
2017-06-02 12:54:21 +00:00
|
|
|
#include "display.h"
|
2017-05-31 22:12:03 +00:00
|
|
|
#include "xcb.h"
|
2016-01-07 15:01:56 +00:00
|
|
|
#include "settings.h"
|
2017-05-04 12:54:38 +00:00
|
|
|
#include "xrmoptions.h"
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2015-09-16 19:01:40 +00:00
|
|
|
static int test = 0;
|
|
|
|
unsigned int normal_window_mode = 0;
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
#define TASSERT( a ) { \
|
|
|
|
assert ( a ); \
|
|
|
|
printf ( "Test %3i passed (%s)\n", ++test, # a ); \
|
2014-08-30 18:45:08 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 13:27:36 +00:00
|
|
|
#include "view.h"
|
2017-01-09 22:15:45 +00:00
|
|
|
|
2017-09-17 16:17:26 +00:00
|
|
|
gboolean config_parse_set_property ( G_GNUC_UNUSED const Property *p, G_GNUC_UNUSED char **error )
|
2017-03-28 10:08:14 +00:00
|
|
|
{
|
2017-06-20 19:02:13 +00:00
|
|
|
return FALSE;
|
2017-03-28 10:08:14 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 15:57:08 +00:00
|
|
|
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg)
|
2017-01-09 22:15:45 +00:00
|
|
|
{
|
|
|
|
}
|
2016-02-06 12:06:58 +00:00
|
|
|
void rofi_view_queue_redraw ()
|
2016-01-20 19:57:26 +00:00
|
|
|
{
|
2016-02-28 00:21:22 +00:00
|
|
|
}
|
2017-05-03 15:57:08 +00:00
|
|
|
void rofi_view_get_current_monitor ( G_GNUC_UNUSED int *width, G_GNUC_UNUSED int *height )
|
2017-01-03 18:35:23 +00:00
|
|
|
{
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2017-01-03 18:35:23 +00:00
|
|
|
}
|
2016-03-03 07:23:12 +00:00
|
|
|
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
2015-07-28 20:22:18 +00:00
|
|
|
{
|
|
|
|
fputs ( msg, stderr );
|
2016-03-03 07:23:12 +00:00
|
|
|
return FALSE;
|
2015-07-28 20:22:18 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 22:12:03 +00:00
|
|
|
int monitor_active ( G_GNUC_UNUSED workarea *mon )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-02 12:54:21 +00:00
|
|
|
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:58:17 +00:00
|
|
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
2014-08-30 18:45:08 +00:00
|
|
|
{
|
2016-02-28 14:32:53 +00:00
|
|
|
cairo_surface_t *surf = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, 100, 100 );
|
|
|
|
cairo_t *draw = cairo_create ( surf );
|
|
|
|
PangoContext *p = pango_cairo_create_context ( draw );
|
2017-04-10 07:27:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
textbox_setup();
|
2017-01-26 16:40:46 +00:00
|
|
|
textbox_set_pango_context ( "default", p );
|
2015-12-28 10:33:22 +00:00
|
|
|
|
2017-04-10 07:27:22 +00:00
|
|
|
|
2017-09-07 11:46:09 +00:00
|
|
|
textbox *box = textbox_create ( NULL, WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "test",0,0 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box != NULL );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_END );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_cursor ( box, -1 );
|
2015-07-28 19:54:08 +00:00
|
|
|
TASSERT ( box->cursor == 0 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_cursor ( box, 8 );
|
2015-07-28 19:54:08 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_cursor ( box, 2 );
|
2015-07-28 19:54:08 +00:00
|
|
|
TASSERT ( box->cursor == 2 );
|
2015-11-22 19:41:45 +00:00
|
|
|
textbox_insert ( box, 3, "bo", 2 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "tesbot" ) == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_END );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 6 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-08 16:57:59 +00:00
|
|
|
TASSERT ( widget_get_width ( WIDGET ( box ) ) > 0 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( textbox_get_height ( box ) > 0 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-08 16:57:59 +00:00
|
|
|
TASSERT ( widget_get_width ( WIDGET ( box ) ) >= textbox_get_font_width ( box ) );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( textbox_get_height ( box ) >= textbox_get_font_height ( box ) );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( textbox_get_estimated_char_width ( ) > 0 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, REMOVE_CHAR_BACK );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "tesbo" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 5 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_CHAR_BACK );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, REMOVE_CHAR_FORWARD );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "tesb" ) == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_CHAR_BACK );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 3 );
|
2016-10-25 19:19:39 +00:00
|
|
|
textbox_keybinding ( box, MOVE_CHAR_FORWARD );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2016-10-25 19:19:39 +00:00
|
|
|
textbox_keybinding ( box, MOVE_CHAR_FORWARD );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2014-08-30 18:45:08 +00:00
|
|
|
// Cursor after delete section.
|
|
|
|
textbox_delete ( box, 0, 1 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "esb" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 3 );
|
2014-08-30 18:45:08 +00:00
|
|
|
// Cursor before delete.
|
2015-07-28 20:14:21 +00:00
|
|
|
textbox_text ( box, "aap noot mies" );
|
|
|
|
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
|
|
|
|
textbox_cursor ( box, 3 );
|
|
|
|
TASSERT ( box->cursor == 3 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_delete ( box, 3, 6 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 3 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
|
|
|
// Cursor within delete
|
2015-07-28 20:14:21 +00:00
|
|
|
textbox_text ( box, "aap noot mies" );
|
|
|
|
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
|
|
|
|
textbox_cursor ( box, 5 );
|
|
|
|
TASSERT ( box->cursor == 5 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_delete ( box, 3, 6 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 3 );
|
2015-07-28 19:54:08 +00:00
|
|
|
// Cursor after delete.
|
2015-07-28 20:14:21 +00:00
|
|
|
textbox_text ( box, "aap noot mies" );
|
|
|
|
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
|
|
|
|
textbox_cursor ( box, 11 );
|
|
|
|
TASSERT ( box->cursor == 11 );
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_delete ( box, 3, 6 );
|
2015-07-28 20:14:21 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 5 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-10-25 19:19:39 +00:00
|
|
|
textbox_text ( box, "aap noot mies" );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_cursor ( box, 8 );
|
|
|
|
textbox_keybinding ( box, REMOVE_WORD_BACK );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
|
|
|
TASSERT ( strcmp ( box->text, "aap mies" ) == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, REMOVE_TO_EOL );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
|
|
|
TASSERT ( strcmp ( box->text, "aap " ) == 0 );
|
|
|
|
textbox_text ( box, "aap noot mies" );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_cursor ( box, 8 );
|
|
|
|
textbox_keybinding ( box, REMOVE_WORD_FORWARD );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "aap noot" ) == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_FRONT );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( box->cursor == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, CLEAR_LINE );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "" ) == 0 );
|
|
|
|
textbox_text ( box, "aap noot mies" );
|
|
|
|
textbox_keybinding ( box, MOVE_END );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_WORD_BACK );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( box->cursor == 9 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, MOVE_WORD_BACK );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( box->cursor == 4 );
|
2016-10-20 07:41:32 +00:00
|
|
|
textbox_keybinding ( box, REMOVE_TO_SOL );
|
2016-10-25 19:19:39 +00:00
|
|
|
TASSERT ( strcmp ( box->text, "noot mies" ) == 0 );
|
|
|
|
TASSERT ( box->cursor == 0 );
|
2016-10-20 07:41:32 +00:00
|
|
|
|
2014-08-30 18:45:08 +00:00
|
|
|
textbox_font ( box, HIGHLIGHT );
|
2016-02-28 00:21:22 +00:00
|
|
|
//textbox_draw ( box, draw );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-01-09 18:25:03 +00:00
|
|
|
widget_move ( WIDGET ( box ), 12, 13 );
|
2016-01-09 15:22:09 +00:00
|
|
|
TASSERT ( box->widget.x == 12 );
|
|
|
|
TASSERT ( box->widget.y == 13 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2016-09-27 20:38:26 +00:00
|
|
|
widget_free ( WIDGET ( box ) );
|
2015-07-28 20:14:21 +00:00
|
|
|
textbox_cleanup ( );
|
2014-08-30 18:45:08 +00:00
|
|
|
}
|