From 2ea6389b03afd2b315cab28ade3414cfcf939f74 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 23 Oct 2011 04:16:53 +0000 Subject: made window_name from new canvas_name svn path=/trunk/externals/hcs/; revision=15643 --- canvas_name-help.pd | 12 +++--- canvas_name.c | 2 - window_name-help.pd | 109 +++++++++++++++++++++++++++++++++++++++------------- window_name.c | 107 +++++++++++++++++++++++++++++++-------------------- 4 files changed, 155 insertions(+), 75 deletions(-) diff --git a/canvas_name-help.pd b/canvas_name-help.pd index 5d1c03e..56c9b81 100644 --- a/canvas_name-help.pd +++ b/canvas_name-help.pd @@ -5,7 +5,7 @@ #X msg 136 260 \$2 configure -background \$1; #X obj 136 231 pack symbol symbol; #X obj 86 64 colorpanel; -#X obj 67 356 pddp/pddplink http://tcl.tk/man/tcl8.4/TkCmd/canvas.htm +#X obj 67 356 pddp/pddplink http://tcl.tk/man/tcl8.5/TkCmd/canvas.htm ; #X text 34 330 for more options:; #N canvas 685 90 416 325 generate 0; @@ -166,9 +166,9 @@ how many levels up you want to get:; #X symbolatom 260 406 10 0 0 0 - - -; #X obj 260 338 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 -1 0; -#X text 121 429 .x0.c means a non-existant window; #X floatatom 271 360 5 0 0 0 - - -; #X msg 139 335 2; +#X text 121 429 .x0.c means a non-existant canvas; #X connect 1 0 0 0; #X connect 2 0 1 0; #X connect 4 0 5 0; @@ -184,8 +184,8 @@ how many levels up you want to get:; #X connect 22 0 6 0; #X connect 23 0 13 0; #X connect 26 0 21 0; -#X connect 26 0 28 0; -#X connect 29 0 17 0; +#X connect 26 0 27 0; +#X connect 28 0 17 0; #X restore 265 51 pd get from different levels; #N canvas 196 75 460 490 get 0; #X symbolatom 77 428 0 0 0 0 - - -; @@ -212,8 +212,8 @@ canvas_name:; #X obj 72 155 canvas_name pd-getmyname; #X msg 79 351 myname; #X msg 64 325 symbol this_does_not_exist; -#X text 91 459 .x0.c means a non-existant window; #X msg 129 351 symbol pd-getmyname; +#X text 91 459 .x0.c means a non-existant canvas; #X connect 2 0 16 0; #X connect 5 0 6 0; #X connect 6 0 4 0; @@ -224,7 +224,7 @@ canvas_name:; #X connect 16 0 1 0; #X connect 17 0 8 0; #X connect 18 0 8 0; -#X connect 20 0 8 0; +#X connect 19 0 8 0; #X restore 265 76 pd get by canvas receive symbol; #N canvas 410 155 494 344 META 0; #X text 12 125 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan diff --git a/canvas_name.c b/canvas_name.c index cf27875..d8fa11a 100644 --- a/canvas_name.c +++ b/canvas_name.c @@ -3,8 +3,6 @@ #include #include "g_canvas.h" -/* TODO make the query level settable by 2nd inlet */ - #define DEBUG(x) static t_class *canvas_name_class; diff --git a/window_name-help.pd b/window_name-help.pd index e55c8c0..363dcfc 100644 --- a/window_name-help.pd +++ b/window_name-help.pd @@ -1,18 +1,17 @@ -#N canvas 0 26 576 352 10; +#N canvas 111 51 576 352 10; #X obj 124 207 sys_gui; #X symbolatom 239 101 0 0 0 0 - - -; #X obj 223 32 loadbang; #X obj 124 148 pack float symbol; #X obj 59 88 hsl 128 15 0.1 1 1 1 empty empty window_alpha -2 -8 0 -10 -204800 -1 -1 200 1; +10 -204800 -1 -1 12700 1; #X floatatom 56 123 5 0 0 0 - - -; #X msg 124 177 wm attributes \$2 -alpha \$1; #X text 210 274 for more options:; -#X obj 241 292 pddp/pddplink http://tcl.tk/man/tcl8.4/TkCmd/wm.htm +#X obj 241 292 pddp/pddplink http://tcl.tk/man/tcl8.5/TkCmd/wm.htm ; #X text 113 234 alpha does not work with X11 :(; #X obj 223 69 window_name; -#X obj 375 248 sys_gui; #X text 13 37 change alpha of this window:; #N canvas 83 292 729 228 Mac 0; #X obj 25 163 sys_gui; @@ -96,7 +95,7 @@ #X connect 17 0 5 0; #X connect 20 0 0 0; #X restore 60 297 pd Windows tricks; -#N canvas 574 137 450 300 get 0; +#N canvas 228 139 462 430 get 0; #X symbolatom 42 235 0 0 0 0 - - -; #X obj 42 191 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; @@ -139,6 +138,43 @@ one is embedded in by setting the argument to the level:; #X restore 299 214 pd get parent of parent; #X obj 73 107 window_name 1; #X obj 42 214 window_name; +#X text 45 278 get the canvas name using a float message representing +depth; +#X symbolatom 103 359 10 0 0 0 - - -; +#X msg 88 305 0; +#X msg 118 305 1; +#N canvas 0 22 450 300 open 0; +#N canvas 511 55 450 300 open 0; +#X obj 131 37 inlet; +#X obj 129 109 outlet; +#N canvas 772 55 450 300 open 0; +#X obj 131 37 inlet; +#X obj 129 109 outlet; +#N canvas 0 22 450 300 open 0; +#X obj 141 47 inlet; +#X obj 139 119 outlet; +#X obj 143 84 window_name; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X restore 128 76 pd open me; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X restore 129 74 pd open me; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X restore 138 87 pd open me; +#X obj 141 47 inlet; +#X obj 139 119 outlet; +#X connect 0 0 2 0; +#X connect 1 0 0 0; +#X restore 270 352 pd open me; +#X symbolatom 270 376 10 0 0 0 - - -; +#X obj 270 308 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 +-1 -1 6; +#X text 131 399 .x0.c means a non-existant window; +#X floatatom 281 330 5 0 0 0 - - -; +#X msg 149 305 2; +#X obj 104 333 window_name; #X connect 1 0 16 0; #X connect 3 0 4 0; #X connect 4 0 2 0; @@ -149,43 +185,63 @@ one is embedded in by setting the argument to the level:; #X connect 14 0 12 0; #X connect 15 0 8 0; #X connect 16 0 0 0; +#X connect 19 0 27 0; +#X connect 20 0 27 0; +#X connect 21 0 22 0; +#X connect 23 0 21 0; +#X connect 23 0 25 0; +#X connect 26 0 27 0; +#X connect 27 0 18 0; #X restore 336 39 pd get from different levels; -#N canvas 1197 96 450 300 get 0; +#N canvas 692 51 454 468 get 0; #X symbolatom 73 259 0 0 0 0 - - -; #X obj 73 215 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X symbolatom 72 176 0 0 0 0 - - -; #X obj 72 132 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#N canvas 0 22 450 300 test 0; -#X symbolatom 188 150 0 0 0 0 - - -; -#X obj 188 106 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 --1 -1; -#X obj 188 129 window_name; -#X connect 1 0 2 0; -#X connect 2 0 0 0; -#X restore 221 155 pd test; #X obj 220 77 namecanvas myname; #X symbolatom 73 99 0 0 0 0 - - -; #X obj 73 55 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X text 53 14 You can also use the canvas receive symbol to get the canvas_name:; -#X obj 72 155 window_name pd-test; #X obj 73 78 window_name myname; #X obj 73 238 window_name pd-window_name-help.pd; -#X connect 1 0 11 0; -#X connect 3 0 9 0; -#X connect 7 0 10 0; -#X connect 9 0 2 0; -#X connect 10 0 6 0; -#X connect 11 0 0 0; +#X symbolatom 97 418 0 0 0 0 - - -; +#X text 69 292 or via the inlet:; +#X msg 99 341 myname; +#X msg 84 315 symbol this_does_not_exist; +#X msg 149 341 symbol pd-getmyname; +#X text 111 439 .x0 means a non-existant window; +#X obj 72 155 window_name pd-getmyname; +#N canvas 0 22 450 300 getmyname 0; +#X symbolatom 188 150 0 0 0 0 - - -; +#X obj 188 106 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X obj 188 129 window_name; +#X connect 1 0 2 0; +#X connect 2 0 0 0; +#X restore 231 155 pd getmyname; +#X msg 149 366 pd-window_name-help.pd; +#X obj 97 397 window_name; +#X connect 1 0 9 0; +#X connect 3 0 16 0; +#X connect 6 0 8 0; +#X connect 8 0 5 0; +#X connect 9 0 0 0; +#X connect 12 0 19 0; +#X connect 13 0 19 0; +#X connect 14 0 19 0; +#X connect 16 0 2 0; +#X connect 18 0 19 0; +#X connect 19 0 10 0; #X restore 336 64 pd get by canvas receive symbol; #X text 341 114 turn on/off resizing of this window:; #X obj 474 177 window_name; #X obj 375 197 pack float symbol; #X obj 474 157 loadbang; -#X obj 375 155 tgl 30 0 empty empty empty 17 7 0 10 -204786 -1 -1 0 +#X obj 375 155 tgl 30 0 empty empty empty 17 7 0 10 -204786 -1 -1 1 1; #X msg 375 222 wm resizable \$2 \$1 \$1; #N canvas 398 189 494 344 META 0; @@ -198,6 +254,7 @@ Wilkes for Pd version 0.42.; #X text 12 65 INLET_0 bang; #X text 12 85 OUTLET_0 symbol; #X restore 525 330 pd META; +#X obj 375 248 sys_gui; #X connect 2 0 10 0; #X connect 3 0 6 0; #X connect 4 0 3 0; @@ -205,8 +262,8 @@ Wilkes for Pd version 0.42.; #X connect 6 0 0 0; #X connect 10 0 3 1; #X connect 10 0 1 0; -#X connect 18 0 19 1; -#X connect 19 0 22 0; +#X connect 17 0 18 1; +#X connect 18 0 21 0; +#X connect 19 0 17 0; #X connect 20 0 18 0; -#X connect 21 0 19 0; -#X connect 22 0 11 0; +#X connect 21 0 23 0; diff --git a/window_name.c b/window_name.c index b6ccd3d..0528e9f 100644 --- a/window_name.c +++ b/window_name.c @@ -6,71 +6,96 @@ #define DEBUG(x) static t_class *window_name_class; -static t_canvas *canvas; typedef struct _window_name { - t_object x_obj; - t_atom x_atom; - t_symbol *x_window_name; - t_symbol *x_remote_name; + t_object x_obj; + t_canvas *x_canvas; + t_symbol *receive_name; + t_int depth; } t_window_name; -static void window_name_bang(t_window_name *x) +static t_symbol* make_canvas_symbol(t_canvas* canvas) { - if (x->x_atom.a_type == A_SYMBOL) - { - canvas=(t_canvas *)pd_findbyclass(x->x_remote_name, canvas_class); char buf[MAXPDSTRING]; - snprintf(buf, MAXPDSTRING, ".x%lx", (long unsigned int)canvas); - x->x_window_name = gensym(buf); - } - outlet_symbol(x->x_obj.ob_outlet,x->x_window_name); + return gensym(buf); } -static void *window_name_new(t_symbol *s, int argc, t_atom *argv) +static t_symbol* get_canvas_by_depth(t_window_name *x) { - t_atom a; - if (argc == 0) + t_canvas *canvas = x->x_canvas; + int depth = x->depth; + if(depth<0)depth=0; + while(depth && canvas) { - argc = 1; - SETFLOAT(&a, 0); - argv = &a; + canvas = canvas->gl_owner; + depth--; } - t_window_name *x = (t_window_name *)pd_new(window_name_class); - x->x_atom = *argv; - if (argv->a_type == A_FLOAT) - { // thx to IOhannes's iemguts: - t_glist *glist=(t_glist *)canvas_getcurrent(); - canvas=(t_canvas *)glist_getcanvas(glist); - int depth=(int)atom_getint(&x->x_atom); + return make_canvas_symbol(canvas); +} - if(depth<0)depth=0; - while(depth && canvas) { - canvas=canvas->gl_owner; - depth--; - } - char buf[MAXPDSTRING]; +static t_symbol* get_canvas_by_name(t_window_name *x) +{ + return make_canvas_symbol((t_canvas *)pd_findbyclass(x->receive_name, canvas_class)); +} - snprintf(buf, MAXPDSTRING, ".x%lx", (long unsigned int)canvas); - x->x_window_name = gensym(buf); - } +static t_symbol* get_window_name(t_window_name *x) +{ + if(x->receive_name == &s_) + return get_canvas_by_depth(x); else - { - x->x_remote_name = (t_symbol *)atom_getsymbol(&x->x_atom); - } + return get_canvas_by_name(x); +} + +static void window_name_bang(t_window_name *x) +{ + /* actually get the canvas name each time to make sure we get + * accurate info in case of changes. If we cache the result, a + * canvas could have been deleted or renamed. */ + outlet_symbol(x->x_obj.ob_outlet, get_window_name(x)); +} + +static void window_name_anything(t_window_name *x, t_symbol *s, int argc, t_atom *argv) +{ + t_symbol *first_symbol = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(s == &s_float) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else if (first_symbol == &s_) + x->receive_name = s; + else + x->receive_name = first_symbol; + window_name_bang(x); +} + +static void *window_name_new(t_symbol *s, int argc, t_atom *argv) +{ + t_window_name *x = (t_window_name *)pd_new(window_name_class); + + t_glist* glist = (t_glist *)canvas_getcurrent(); + x->x_canvas = (t_canvas *)glist_getcanvas(glist); + + t_symbol *tmp = atom_getsymbolarg(0,argc,argv); + x->depth = 0; + x->receive_name = &s_; + if(tmp == &s_) + x->depth = (t_int) atom_getfloatarg(0,argc,argv); + else + x->receive_name = tmp; - outlet_new(&x->x_obj, &s_symbol); + outlet_new(&x->x_obj, &s_symbol); return(x); } void window_name_setup(void) { - window_name_class = class_new(gensym("window_name"), - (t_newmethod)window_name_new, NULL, + window_name_class = class_new(gensym("window_name"), + (t_newmethod)window_name_new, NULL, sizeof(t_window_name), 0, A_GIMME, 0); class_addbang(window_name_class, (t_method)window_name_bang); + class_addanything(window_name_class, (t_method)window_name_anything); } -- cgit v1.2.1