]>
iEval git - xfishtank.git/blob - src/utils.c
2260b79e60c7e8b2cafe37b42e7a45f90f0fe8a6
2 #-# Copyright © 2021 Eric Bina, Dave Black, TJ Phan,
3 #-# Vincent Renardias, Willem Vermin
5 #-# Permission is hereby granted, free of charge, to any person
6 #-# obtaining a copy of this software and associated documentation
7 #-# files (the “Software”), to deal in the Software without
8 #-# restriction, including without limitation the rights to use,
9 #-# copy, modify, merge, publish, distribute, sublicense, and/or
10 #-# sell copies of the Software, and to permit persons to whom
11 #-# the Software is furnished to do so, subject to the following
14 #-# The above copyright notice and this permission notice shall
15 #-# be included in all copies or substantial portions of the Software.
17 #-# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18 #-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 #-# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 #-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 #-# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 #-# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 #-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 #-# OTHER DEALINGS IN THE SOFTWARE.
34 #include <X11/Intrinsic.h>
37 #include "xfishtank.h"
42 ssize_t
mywrite(int fd
, const void *buf
, size_t count
)
44 const size_t m
= 4096; // max per write
45 size_t w
= 0; // # written chars
46 char *b
= (char *)buf
;
53 ssize_t x
= write(fd
, b
+w
, l
);
61 FILE *HomeOpen(const char *file
,const char *mode
, char **path
)
63 char *h
= getenv("HOME");
66 char *home
= strdup(h
);
67 (*path
) = (char *) malloc((strlen(home
)+strlen(file
)+2)*sizeof(char));
71 FILE *f
= fopen(*path
,mode
);
77 float sq3(float x
, float y
, float z
)
79 return x
*x
+ y
*y
+ z
*z
;
82 float sq2(float x
, float y
)
90 if (x
<0) return -1.0f
;
109 int is_little_endian(void)
112 return (*(char *)&endiantest
) == 1;
115 void my_cairo_paint_with_alpha(cairo_t
*cr
, double alpha
)
120 cairo_paint_with_alpha(cr
,alpha
);
121 P("%d alpha %f\n",counter
++,alpha
);
125 * Window_With_Name: routine to locate a window with a given name on a display.
126 * If no window with the given name is found, 0 is returned.
127 * If more than one window has the given name, the first
128 * one found will be returned. Only top and its subwindows
129 * are looked at. Normally, top should be the RootWindow.
131 Window
Window_With_Name( Display
*dpy
, Window top
, const char *name
)
133 Window
*children
, dummy
;
134 unsigned int nchildren
;
139 // this leaks memory:
140 //if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
143 if (XFetchName(dpy
, top
, &window_name
) && !strcmp(window_name
, name
))
150 if (!XQueryTree(dpy
, top
, &dummy
, &dummy
, &children
, &nchildren
))
155 for (i
=0; (unsigned int)i
<nchildren
; i
++) {
156 w
= Window_With_Name(dpy
, children
[i
], name
);
160 if (children
) XFree ((char *)children
);
167 return (double)g_get_real_time()*1.0e-6;
172 return (double)g_get_monotonic_time()*1.0e-6;
176 // usage of strncpy gives useless warning "-Wstringop-truncation",
177 // so here is a local version:
178 void mystrncpy(char *dest
, const char *src
, size_t n
)
180 // see if there is a null-byte within src. In that case we do a strcpy:
182 for (i
= 0; i
<n
; i
++)
191 // simply copy n chars:
193 memcpy(dest
,src
,n
*sizeof(char));
196 void rgba2color(GdkRGBA
*c
, char **s
)
198 *s
= (char *)malloc(8);
199 sprintf(*s
,"#%02lx%02lx%02lx",lrint(c
->red
*255),lrint(c
->green
*255),lrint(c
->blue
*255));
This page took 0.044973 seconds and 4 git commands to generate.