1 #include "subtitler.h"
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 
6 #include <X11/Intrinsic.h>
7 #include <X11/Xaw/Simple.h>
8 
9 #include "x11.h"
10 
11 extern int debug_flag;
12 
13 XtAppContext app_context;
14 Widget app_shell, tv;
15 Display *dpy;
16 static XImage *grab_ximage = NULL;
17 static GC grab_gc;
18 static unsigned int display_bits = 0;
19 
20 
putimage(int xsize,int ysize)21 void putimage(int xsize, int ysize)
22 {
23 if (grab_ximage)
24 	{
25 	XPutImage(dpy, XtWindow(tv), grab_gc, grab_ximage, 0, 0, 0, 0,\
26 	xsize, ysize);
27 
28 	XFlush(dpy);
29 	}
30 }/* end function putimage */
31 
32 
openwin(int argc,char * argv[],int xsize,int ysize)33 int openwin(int argc, char *argv[], int xsize, int ysize)
34 {
35 static Window root;
36 XVisualInfo	*info, template;
37 int found;
38 
39 app_shell =\
40 XtAppInitialize(\
41 &app_context, "subtitler by Panteltje (c)",\
42 NULL, 0, &argc, argv, NULL, NULL, 0);
43 
44 XtMakeResizeRequest(app_shell, xsize, ysize, NULL, NULL);
45 
46 dpy = XtDisplay(app_shell);
47 
48 root = DefaultRootWindow(dpy);
49 
50 template.screen = XDefaultScreen(dpy);
51 
52 template.visualid =\
53 XVisualIDFromVisual(DefaultVisualOfScreen(DefaultScreenOfDisplay(dpy)));
54 
55 info =\
56 XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &template,&found);
57 if (!info)
58 	{
59 	tc_log_warn(MOD_NAME, "XGetVisualInfo failed");
60 	return -1;
61 	}
62 
63 display_bits = info -> depth;
64 
65 //UNCOMMENT ONE OF THESE LINES IF YOU WANT FIXED COLOR DEPTH.
66 //display_bits = 16;
67 //display_bits = 24;
68 //display_bits = 32;
69 
70 if(debug_flag)
71 	{
72 	tc_log_msg(MOD_NAME,
73 	"x11: color depth: %u bits", display_bits);
74 
75 	tc_log_msg(MOD_NAME,
76 	"x11: color masks: red=0x%08lx green=0x%08lx blue=0x%08lx",
77 	info->red_mask, info->green_mask, info->blue_mask);
78 	}
79 
80 XFree(info);
81 
82 tv = XtVaCreateManagedWidget("tv", simpleWidgetClass, app_shell,NULL);
83 
84 XtRegisterDrawable(dpy, root, tv);
85 
86 XtRealizeWidget(app_shell);
87 
88 grab_gc = XCreateGC(dpy, XtWindow(tv), 0, NULL);
89 
90 grab_ximage =\
91 XCreateImage(dpy, DefaultVisualOfScreen(DefaultScreenOfDisplay(dpy)),\
92 	DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)),\
93 	ZPixmap, 0, malloc(xsize * ysize * 4), // depth / 8  (24 / 8)? just 2 be on the safe side
94 	xsize, ysize, 8, 0);
95 
96 XClearArea(XtDisplay(tv), XtWindow(tv), 0, 0, 0, 0, True);
97 
98 return 0;
99 }/* end function openwin */
100 
101 
getbuf(void)102 unsigned char *getbuf(void)
103 {
104 if (!grab_ximage)
105 	{
106 	tc_log_error(MOD_NAME, "grab_ximage == NULL shouldn't be!\n");
107 	}
108 return grab_ximage -> data;
109 }/* end function getbuf */
110 
111 
closewin(void)112 void closewin(void)
113 {
114 if(debug_flag)
115 	{
116 	tc_log_msg(MOD_NAME, "closewin(): arg none\n");
117 	}
118 
119 XtDestroyWidget(app_shell);
120 return;
121 
122 XtUnrealizeWidget(app_shell);
123 
124 if(tv) XtDestroyWidget(tv);
125 
126 if(grab_ximage) XDestroyImage(grab_ximage);
127 
128 }/* end function closewin */
129 
130 
get_x11_bpp()131 int get_x11_bpp()
132 {
133 return display_bits;
134 }/* end function get_x11_bpp */
135 
136 
resize_window(int xsize,int ysize)137 int resize_window(int xsize, int ysize)
138 {
139 XtMakeResizeRequest(app_shell, xsize, ysize, NULL, NULL);
140 
141 return 1;
142 }/* end function resize_window */
143 
144