summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2020-07-22 23:46:49 +0200
committerBoris Faure <billiob@gmail.com>2020-07-22 23:46:49 +0200
commit3c21c13d39ed9a48c4ea5a56c4d901525465f1fc (patch)
tree149b75a7fdc71975c76ed4794fd0be16a1ad926e
parent6b8409dfda313c1cdb9aa74238d50021973cd967 (diff)
about: add context menu on twitter link
-rw-r--r--data/themes/default/base.edc6
-rw-r--r--src/bin/about.c93
2 files changed, 98 insertions, 1 deletions
diff --git a/data/themes/default/base.edc b/data/themes/default/base.edc
index 29c5911..e835479 100644
--- a/data/themes/default/base.edc
+++ b/data/themes/default/base.edc
@@ -374,10 +374,14 @@ group { name: "terminology/base";
374 target: "twitter.r"; 374 target: "twitter.r";
375 } 375 }
376 program { 376 program {
377 signal: "mouse,down,1"; source: "twitter.txt"; 377 signal: "mouse,clicked,1"; source: "twitter.txt";
378 action: SIGNAL_EMIT "about,twitter" "terminology"; 378 action: SIGNAL_EMIT "about,twitter" "terminology";
379 } 379 }
380 program { 380 program {
381 signal: "mouse,clicked,3"; source: "twitter.txt";
382 action: SIGNAL_EMIT "about,twitter,ctx" "terminology";
383 }
384 program {
381 signal: "about,show"; source: "terminology"; 385 signal: "about,show"; source: "terminology";
382 action: STATE_SET "visible" 0.0; 386 action: STATE_SET "visible" 0.0;
383 transition: SPRING 1.2 2.0 6; 387 transition: SPRING 1.2 2.0 6;
diff --git a/src/bin/about.c b/src/bin/about.c
index 4a9d937..c19278c 100644
--- a/src/bin/about.c
+++ b/src/bin/about.c
@@ -6,6 +6,7 @@
6#include "config.h" 6#include "config.h"
7#include "termio.h" 7#include "termio.h"
8 8
9#define TWITTER_HANDLE "@_Terminology_"
9 10
10typedef struct _about_ctx { 11typedef struct _about_ctx {
11 Evas_Object *layout; 12 Evas_Object *layout;
@@ -13,6 +14,7 @@ typedef struct _about_ctx {
13 Evas_Object *win; 14 Evas_Object *win;
14 Evas_Object *base; 15 Evas_Object *base;
15 Evas_Object *term; 16 Evas_Object *term;
17 Evas_Object *ctxpopup;
16 void (*donecb) (void *data); 18 void (*donecb) (void *data);
17 void *donedata; 19 void *donedata;
18 Config *config; 20 Config *config;
@@ -44,6 +46,58 @@ _run_url(const About_Ctx *ctx,
44} 46}
45 47
46static void 48static void
49_cb_ctxpopup_del(void *data,
50 Evas *_e EINA_UNUSED,
51 Evas_Object *_obj EINA_UNUSED,
52 void *_event EINA_UNUSED)
53{
54 About_Ctx *ctx = data;
55
56 ctx->ctxpopup = NULL;
57}
58
59static void
60_cb_ctxpopup_dismissed(void *data,
61 Evas_Object *obj,
62 void *_event EINA_UNUSED)
63{
64 About_Ctx *ctx = data;
65
66 ctx->ctxpopup = NULL;
67 evas_object_del(obj);
68}
69
70static void
71_cb_ctxpopup_copy_twitter(void *data,
72 Evas_Object *obj,
73 void *_event EINA_UNUSED)
74{
75 About_Ctx *ctx = data;
76
77 elm_cnp_selection_set(ctx->win, ELM_SEL_TYPE_CLIPBOARD,
78 ELM_SEL_FORMAT_TEXT,
79 TWITTER_HANDLE,
80 strlen(TWITTER_HANDLE));
81 ctx->ctxpopup = NULL;
82 evas_object_del(obj);
83}
84
85static void
86_cb_ctxpopup_open_twitter_as_url(void *data,
87 Evas_Object *obj,
88 void *_event EINA_UNUSED)
89{
90 About_Ctx *ctx = data;
91
92 _run_url(ctx, "https://twitter.com/_Terminology_");
93
94 ctx->ctxpopup = NULL;
95 evas_object_del(obj);
96}
97
98
99
100static void
47_cb_twitter(void *data, 101_cb_twitter(void *data,
48 Evas_Object *_obj EINA_UNUSED, 102 Evas_Object *_obj EINA_UNUSED,
49 const char *_sig EINA_UNUSED, 103 const char *_sig EINA_UNUSED,
@@ -55,6 +109,38 @@ _cb_twitter(void *data,
55} 109}
56 110
57static void 111static void
112_cb_twitter_ctx(void *data,
113 Evas_Object *_obj EINA_UNUSED,
114 const char *_sig EINA_UNUSED,
115 const char *_src EINA_UNUSED)
116{
117 About_Ctx *ctx = data;
118 Evas_Object *popup;
119 const char *fmt;
120 Evas *e = evas_object_evas_get(ctx->base);
121 Evas_Coord x;
122 Evas_Coord y;
123
124 evas_pointer_canvas_xy_get(e, &x, &y);
125
126 popup = elm_ctxpopup_add(ctx->win);
127 ctx->ctxpopup = popup;
128 fmt = eina_stringshare_printf(_("Copy '%s'"),
129 TWITTER_HANDLE);
130
131 elm_ctxpopup_item_append(popup, fmt, NULL,
132 _cb_ctxpopup_copy_twitter, ctx);
133 elm_ctxpopup_item_append(popup, _("Open"), NULL,
134 _cb_ctxpopup_open_twitter_as_url, ctx);
135 evas_object_move(popup, x, y);
136 evas_object_show(popup);
137 evas_object_smart_callback_add(popup, "dismissed",
138 _cb_ctxpopup_dismissed, ctx);
139 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL,
140 _cb_ctxpopup_del, ctx);
141}
142
143static void
58_cb_mouse_down(void *data, 144_cb_mouse_down(void *data,
59 Evas *_e EINA_UNUSED, 145 Evas *_e EINA_UNUSED,
60 Evas_Object *_obj EINA_UNUSED, 146 Evas_Object *_obj EINA_UNUSED,
@@ -76,6 +162,8 @@ _cb_mouse_down(void *data,
76 ctx->donecb(ctx->donedata); 162 ctx->donecb(ctx->donedata);
77 elm_layout_signal_callback_del(ctx->base, "about,twitter", "*", 163 elm_layout_signal_callback_del(ctx->base, "about,twitter", "*",
78 _cb_twitter); 164 _cb_twitter);
165 elm_layout_signal_callback_del(ctx->base, "about,twitter,ctx", "*",
166 _cb_twitter_ctx);
79 167
80 free(ctx); 168 free(ctx);
81} 169}
@@ -99,6 +187,9 @@ about_show(Evas_Object *win, Evas_Object *base, Evas_Object *term,
99 ctx->donedata = donedata; 187 ctx->donedata = donedata;
100 ctx->config = config; 188 ctx->config = config;
101 189
190 elm_object_part_text_set(base, "twitter.txt",
191 _("Twitter: @_Terminology_"));
192
102 ctx->layout = o = elm_layout_add(win); 193 ctx->layout = o = elm_layout_add(win);
103 if (elm_layout_file_set(o, config_theme_path_get(config), 194 if (elm_layout_file_set(o, config_theme_path_get(config),
104 "terminology/about") == 0) 195 "terminology/about") == 0)
@@ -227,6 +318,8 @@ about_show(Evas_Object *win, Evas_Object *base, Evas_Object *term,
227 318
228 elm_layout_signal_callback_add(base, "about,twitter", "*", 319 elm_layout_signal_callback_add(base, "about,twitter", "*",
229 _cb_twitter, ctx); 320 _cb_twitter, ctx);
321 elm_layout_signal_callback_add(base, "about,twitter,ctx", "*",
322 _cb_twitter_ctx, ctx);
230 323
231 elm_layout_signal_emit(base, "about,show", "terminology"); 324 elm_layout_signal_emit(base, "about,show", "terminology");
232 elm_object_signal_emit(ctx->layout, "begin" ,"terminology"); 325 elm_object_signal_emit(ctx->layout, "begin" ,"terminology");