Change to the linux kernel coding style
[wmaker-crm.git] / wmlib / app.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* app.c - application context stuff
6830b057 dan2004-10-12 21:28:27 +00002 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00003 * WMlib - WindowMaker application programming interface
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (C) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
6830b057 dan2004-10-12 21:28:27 +000011 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000012 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
6830b057 dan2004-10-12 21:28:27 +000016 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000017 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <X11/Xlib.h>
23#include <stdlib.h>
9aca0d5f dan2004-10-12 01:34:32 +000024#include <string.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000025
26#include "WMaker.h"
27#include "app.h"
28
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020029WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window main_window)
9d2e6ef9 scottc1998-09-29 22:36:29 +000030{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020031 wmAppContext *ctx;
6830b057 dan2004-10-12 21:28:27 +000032
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020033 ctx = malloc(sizeof(wmAppContext));
34 if (!ctx)
35 return NULL;
6830b057 dan2004-10-12 21:28:27 +000036
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020037 ctx->dpy = display;
38 ctx->screen_number = screen_number;
39 ctx->our_leader_hint = False;
40 ctx->main_window = main_window;
41 ctx->windows = malloc(sizeof(Window));
42 if (!ctx->windows) {
43 free(ctx);
44 return NULL;
45 }
46 ctx->win_count = 1;
47 ctx->windows[0] = main_window;
9d2e6ef9 scottc1998-09-29 22:36:29 +000048
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020049 ctx->main_menu = NULL;
6830b057 dan2004-10-12 21:28:27 +000050
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020051 ctx->last_menu_tag = 100;
9d2e6ef9 scottc1998-09-29 22:36:29 +000052
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020053 return ctx;
9d2e6ef9 scottc1998-09-29 22:36:29 +000054}
55
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020056int WMAppAddWindow(WMAppContext * app, Window window)
9d2e6ef9 scottc1998-09-29 22:36:29 +000057{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020058 Window *win;
6830b057 dan2004-10-12 21:28:27 +000059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020060 win = malloc(sizeof(Window) * (app->win_count + 1));
61 if (!win)
62 return False;
9d2e6ef9 scottc1998-09-29 22:36:29 +000063
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020064 memcpy(win, app->windows, sizeof(Window) * app->win_count);
9d2e6ef9 scottc1998-09-29 22:36:29 +000065
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020066 free(app->windows);
088c0ac2 dan1999-03-09 14:58:01 +000067
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020068 win[app->win_count] = window;
69 app->windows = win;
70 app->win_count++;
9d2e6ef9 scottc1998-09-29 22:36:29 +000071
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020072 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +000073}
74
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020075int WMAppSetMainMenu(WMAppContext * app, WMMenu * menu)
9d2e6ef9 scottc1998-09-29 22:36:29 +000076{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020077 app->main_menu = menu;
78 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +000079}