~mmach/netext73/yad-netext

1 by NetBit73
synchronizacja 1
1
/*
2
 * This file is part of YAD.
3
 *
4
 * YAD is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * YAD is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with YAD. If not, see <http://www.gnu.org/licenses/>.
16
 *
23 by mmach
test
17
 * Copyright (C) 2008-2017, Victor Ananjevsky <ananasik@gmail.com>
1 by NetBit73
synchronizacja 1
18
 */
19
20
#include <sys/types.h>
21
#include <sys/stat.h>
22
#include <fcntl.h>
23
#include <stdlib.h>
24
#include <unistd.h>
25
26
#include <sys/ipc.h>
27
#include <sys/shm.h>
28
29
#include <X11/Xlib.h>
30
#include <X11/Xatom.h>
31
#include <X11/Xutil.h>
32
#include <gdk/gdk.h>
33
34
#include "yad.h"
35
36
static GtkWidget *paned;
37
38
GtkWidget *
39
paned_create_widget (GtkWidget * dlg)
40
{
41
  GtkWidget *w, *s;
42
43
  /* get shared memory */
44
  tabs = get_tabs (options.common_data.key, TRUE);
45
  if (!tabs)
46
    exit (-1);
47
48
  /* create widget */
23 by mmach
test
49
  if (options.paned_data.orient == GTK_ORIENTATION_HORIZONTAL)
50
    paned = w = gtk_hpaned_new ();
51
  else
52
    paned = w = gtk_vpaned_new ();
1 by NetBit73
synchronizacja 1
53
  gtk_widget_set_name (w, "yad-paned-widget");
54
55
  gtk_paned_set_position (GTK_PANED (w), options.paned_data.splitter);
56
57
  s = gtk_socket_new ();
58
  gtk_paned_add1 (GTK_PANED (w), s);
59
  g_object_set_data (G_OBJECT (w), "s1", s);
60
61
  s = gtk_socket_new ();
62
  gtk_paned_add2 (GTK_PANED (w), s);
63
  g_object_set_data (G_OBJECT (w), "s2", s);
64
65
  return w;
66
}
67
68
void
69
paned_swallow_childs (void)
70
{
71
  GtkWidget *s1, *s2;
72
73
  s1 = GTK_WIDGET (g_object_get_data (G_OBJECT (paned), "s1"));
74
  s2 = GTK_WIDGET (g_object_get_data (G_OBJECT (paned), "s2"));
75
23 by mmach
test
76
  /* wait until all children are register */
77
  while (tabs[0].xid != 2)
1 by NetBit73
synchronizacja 1
78
    usleep (1000);
79
80
  if (tabs[1].pid != -1)
81
    gtk_socket_add_id (GTK_SOCKET (s1), tabs[1].xid);
82
  if (tabs[2].pid != -1)
83
    gtk_socket_add_id (GTK_SOCKET (s2), tabs[2].xid);
84
}
85
86
void
87
paned_print_result (void)
88
{
89
  if (tabs[1].pid != -1)
90
    kill (tabs[1].pid, SIGUSR1);
91
  if (tabs[2].pid != -1)
92
    kill (tabs[2].pid, SIGUSR1);
93
}
94
95
void
96
paned_close_childs (void)
97
{
98
  guint i;
99
  struct shmid_ds buf;
100
  gboolean is_running = TRUE;
101
102
  if (tabs[1].pid != -1)
103
    kill (tabs[1].pid, SIGUSR2);
104
  if (tabs[2].pid != -1)
105
    kill (tabs[2].pid, SIGUSR2);
106
107
  /* wait for stop subprocesses */
108
  while (is_running)
109
    {
110
      is_running = FALSE;
23 by mmach
test
111
      for (i = 1; i <= 3; i++)
1 by NetBit73
synchronizacja 1
112
        {
113
          if (tabs[i].pid != -1 && kill (tabs[i].pid, 0) == 0)
114
            {
115
              is_running = TRUE;
116
              break;
117
            }
118
        }
23 by mmach
test
119
      usleep (1000);
1 by NetBit73
synchronizacja 1
120
    }
121
122
  /* cleanup shared memory */
123
  shmctl (tabs[0].pid, IPC_RMID, &buf);
124
  shmdt (tabs);
125
}